"123","2"=>"1234","3"=>"1334");$b=array("1"=>"123,"2"=>"1230");怎么得到$c=array("2"=>"12234","3"=>“delete");因为1对应的123 都是"/> "123","2"=>"1234","3"=>"1334");$b=array("1"=>"123,"2"=>"1230");怎么得到$c=array("2"=>"12234","3"=>“delete");因为1对应的123 都是">
PHP数组操作问题
比方说有2个数组$a和$b
$a=array("1"=>"123","2"=>"1234","3"=>"1334");
$b=array("1"=>"123,"2"=>"1230");
怎么得到$c=array("2"=>"12234","3"=>“delete");
因为1对应的123 都是一样 去掉了 2对应的 因为$b比$a小 所以要保留$a的 3因为不存在 所以 后面变成"delete“
------解决方案--------------------
<br />$a = array("1"=>"123","2"=>"1234","3"=>"1334");<br />$b = array("1"=>"123","2"=>"1230");<br /><br />$c = array();<br /><br />foreach($a as $key=>$val){<br />if(isset($b[$key])){<br />if($val!=$b[$key]){<br />$c[$key] = $val>$b[$key]? $val : $b[$key];<br />}<br />}else{<br />$c[$key] = 'delete';<br />}<br />}<br /><br />print_r($c);<br />