Filling the array value if it is missing in the assoc array? I have an :
$A= array("A1"=>array("a"=>1,"b"=>2,"d"=>3),
"A2"=>array("a"=>4,"b"=>3,"c"=>2,"d"=>1)
);
base on the A["A2"] size is bigger than A["A1"] I want got the new $A look like this
$A= array("A1"=>array("a"=>1,"b"=>2,"c"=>"0.00","d"=>3),
"A2"=>array("a"=>4,"开发者_如何学Gob"=>3,"c"=>2,"d"=>1)
);
i'd do it this way:
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';
}
}
}
精彩评论