php foreach循环遍历问题
$list=array('li'=>array('s'=>'L','i'=>'I'),'a'=>'A','b'=>'B');print_r($list);foreach(...
$list = array(
'li'=>array('s'=>'L','i'=>'I'),
'a'=>'A',
'b'=>'B'
);
print_r($list);
foreach ($list as $key => $val)
{
if($list[$key]['s']) {
$list[$key]['s'] = 'l=>L';
}
}
print_r($list);
die;
结果:Array ( [li] => Array ( [s] => L [i] => I ) [a] => A [b] => B ) Array ( [li] => Array ( [s] => l=>L [i] => I ) [a] => l [b] => l )
问:为什么遍历后$list['a'],$list['b']的值都为1,我又没在foreach中设置其值? 展开
'li'=>array('s'=>'L','i'=>'I'),
'a'=>'A',
'b'=>'B'
);
print_r($list);
foreach ($list as $key => $val)
{
if($list[$key]['s']) {
$list[$key]['s'] = 'l=>L';
}
}
print_r($list);
die;
结果:Array ( [li] => Array ( [s] => L [i] => I ) [a] => A [b] => B ) Array ( [li] => Array ( [s] => l=>L [i] => I ) [a] => l [b] => l )
问:为什么遍历后$list['a'],$list['b']的值都为1,我又没在foreach中设置其值? 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询