如果assoc数组中缺少数组值,是否填充该值?我有一个:
$A= array("A1"=>array("a"=>1,"b"=>2,"d"=>3),
"A2"=>array("a"=>4,"b"=>3,"c"=>2,"d"=>1)
);
基于A["A2"]大小大于A["A1"]我想要新的$A,看起来像这个
$A= array("A1"=>array("a"=>1,"b"=>2,"c"=>"0.00","d"=>3),
"A2"=>array("a"=>4,"b"=>3,"c"=>2,"d"=>1)
);
我会这样做:
if (count($A['A2']) > count($A['A1'])){
foreach($A['A2'] as $key => $value){
if (!array_key_exists($key, $A['A1'])){
$A['A1'][$key] = '0.00';
}
}
}