$cartArray structure:
Array ( [0] => 1. X => 2. Y [2] => 3. Z [3] => 4. XX [4] => 5. YY [5] => )
$list:
$list = array(
"1.",
"2.",
"3.",
"4.",
"5."
);
Function
function alignNum($cartArray, $list)
{
foreach($cartArray as $cA)
{
echo "<br />" . $cA . "<br /><br />";
foreach($list as $l)
{
echo $l . "<br />";
echo "Type of \$l is " . gettype($l) . " and type of \$cA is " . gettype($cA) . "<br />";
$pos = strpos($cA, $l);
echo "Comparing " . $l . " to " . $cA . "<br />";
if ($pos !== true)
{
echo "<br />" . $l . " was not found in " . $cA . "<br /><br />";
continue;
}
else
{
$post_cA = str_replace("EUR", "EUR</span>", $cA);
$new_cA[] = (str_replace($l, substr($l, 0, -4) . "<span style='float: right>'", $cA)) . $post_cA;
return $new_cA;
}
}
}
}
$new_cart = alignNum($cart, $list);
So, I keep getting my custom debug message: "X was not found in Y". I.e it's not founding it X in ANY of the provided strings.
It's not a question of types either. Both are strings.
Any ideas?
EDIT: Also, note that I've censored some stuff out, since this is business related code.
It is generally a bad idea (unless you are C programmer) to compare numeric and boolean even in
if ($pos != true)
but in
if ($pos !== true)
AFAIK it will NEVER match because the variables are different types