$cartArray 结构:
Array ( [0] => 1. X => 2. Y [2] => 3. Z [3] => 4. XX [4] => 5. YY [5] => )
$列表:
$list = array(
"1.",
"2.",
"3.",
"4.",
"5."
);
功能
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);
所以,我不断收到我的自定义调试消息:“在 Y 中找不到 X”。即它没有在任何提供的字符串中创建它 X。
这也不是类型的问题。两者都是字符串。
有任何想法吗?
编辑:另外,请注意我已经审查了一些内容,因为这是与业务相关的代码。