PHP数组问题,替换数组元素
多维数组Array([0]=>Array([name]=>[id]=>0)[1]=>Array([name]=>[id]=>0)[2]=>Array([name]=>[a...
多维数组Array ( [0] => Array ( [name] => [id] => 0 ) [1] => Array ( [name] => [id] => 0 ) [2] => Array ( [name] => [aid] => 0 ) [3] => Array ( [name] => admin [id] => 1 ) [4] => Array ( [name] => admin [id] => 1 ))
如果id为0,则把id改成正确,如果id为1,则改为错误 展开
如果id为0,则把id改成正确,如果id为1,则改为错误 展开
1个回答
展开全部
$array = array(
array('name'=>array('id'=>0)),
array('name'=>array('id'=>0)),
array('name'=>array('id'=>0)),
array('name'=>array('id'=>1)),
array('name'=>array('id'=>1)),
);
foreach($array as $k1 => $a1){
foreach($a1 as $k2 => $a2){
if($a2['id'] == 1){
$list[$k1][$k2]['id'] = '正确';
}else{
$list[$k1][$k2]['id'] = '错误';
}
}
}
var_dump($list);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询