"张1","sign"=>""),array('id'=>2,"name"=>"张2","sign"=>""),array('id'=>5,"name"=>"张5","sig">
时间:2021-07-01 10:21:17 帮助过:37人阅读
$ar1=array(array('id'=>1,"name"=>"张1","sign"=>""),array('id'=>2,"name"=>"张2","sign"=>""),array('id'=>5,"name"=>"张5","sign"=>"")); $ar2=array(array('id'=>1,"name"=>"张1"),array('id'=>2,"name"=>"张2"));
$ar1=array(array('id'=>1,"name"=>"张1","sign"=>""),array('id'=>2,"name"=>"张2","sign"=>""),array('id'=>5,"name"=>"张5","sign"=>""));$ar2=array(array('id'=>1,"name"=>"张1"),array('id'=>2,"name"=>"张2"));//先将 $ar2 规格化一下foreach($ar2 as $v) $r[$v['id']] = $v;$ar2 = $r;//接下来就简单了foreach($ar1 as &$v) { if(isset($ar2[$v['id']])) $v['sign'] = 1;}print_r($ar1);
Array( [0] => Array ( [id] => 1 [name] => 张1 [sign] => 1 ) [1] => Array ( [id] => 2 [name] => 张2 [sign] => 1 ) [2] => Array ( [id] => 5 [name] => 张5 [sign] => ))