我的数组返回一些我不想要它们的值并且我从未将它们添加到它中,这非常有趣:
foreach ($this->cart as $c) {
if ($c['parent_id'] != 0) {
$parent_id = $c['parent_id'];
if(in_array($parent_id,$checked_parents))
{
echo 'true';
}else
{
echo 'parent=>'.$parent_id;
echo '<br />';
$checked_parents[] = $parent_id;
$childes[] = array();
foreach($this->cart as $c2)
{
if($c2['parent_id'] == $parent_id)
{
$childes[$c2['id']] = $c2 ;
echo 'added'.$c2['id'];
echo '<br />';
}
}
foreach($childes as $k => $v)
{
echo $k ;
echo '<br />';
if(!$k || $k == 0)
continue;
...
//my other codes
...
我echo
的输出:
parent=>16709
added3
0 // unwanted value ?
3
parent=>16710
added2
added1
0 // unwanted value ?
3 // unwanted value ?
4 // unwanted value ?
2 // it's ok
1 // it's ok
true
不需要的值:
0,3,4
为什么要添加到我的阵列?
答案 0 :(得分:0)
我改变了:
$childes[] = array();
到:
unset($childes);