"1","time"=>"5","neirong"=>"www");$aa=array("id" => "2","時間"=>"55","ネイロン"=>"www");$aa=array("id"=>"4","時間"=>"555","ネイロン」"/> "1","time"=>"5","neirong"=>"www");$aa=array("id" => "2","時間"=>"55","ネイロン"=>"www");$aa=array("id"=>"4","時間"=>"555","ネイロン」">
ホームページ >バックエンド開発 >PHPチュートリアル >2 桁の配列演算について質問します。
2 桁の配列演算について質問します
$aa=array("id"=>"1","time"=>"5","neirong"=>"www");
$ aa=array("id"=>"2","time"=>"55","neirong"=>"www");
$aa=array("id"=> ;" 4","time"=>"555","neirong"=>"www");
$aa=array("id"=>"5","time"=>> "555 ","neirong"=>"www");
$aaa=array("duibi"=>$aa);
$bb=array("id"=> "1 ","時間"=>"5");
$bb=array("id"=>"2","時間"=>"50");
$bb= array( "id"=>"3","time"=>"555");
$bbb=array("duibi"=>$bb);
$aaa および$bbb 比較演算
は
$cc=array("id"=>"2","time"=>"55","neirong"=>"www");$ cc=array("id"=>"3","neirong"=>"削除");
$cc=array("id"=>"4","time"=> ;" 555","neirong"=>"www");
$cc=array("id"=>"5","time"=>"555","neirong"=>> "www ");
書き方
まず説明します
$aa=array("id"=>"1"," time" =>"5","neirong"=>"www");$aa と $bb の時刻が同じであるため、このデータは利用できなくなりました
$aa=array("id" = >"2","time"=>"55","neirong"=>"www");
$bb=array("id"=>"2","time"= >"50");
bbdetime が aa の時間より小さいためです。 。
$cc=array("id"=>"3","neirong"=>"delete");対応する $aa が存在しません。 。
$cc=array("id"=>"4","time"=>"555","neirong"=>"www");
$cc =array("id"=>"5","time"=>"555","neirong"=>"www");
$bb には対応する ID 4 がないため、 5データ。 。つまり
-----解決策---------
$aa = array(<br /> array("id"=>"1","time"=>"5","neirong"=>"www"),<br /> array("id"=>"2","time"=>"55","neirong"=>"www"),<br /> array("id"=>"4","time"=>"555","neirong"=>"www"),<br /> array("id"=>"5","time"=>"555","neirong"=>"www"),<br />);<br /><br />$bb = array(<br /> array("id"=>"1","time"=>"5"),<br /> array("id"=>"2","time"=>"50"),<br /> array("id"=>"3","time"=>"555"),<br />);<br /><br />foreach($aa as $v) $r[$v['id']] = $v;<br />foreach($bb as $v) {<br /> $k = $v['id'];<br /> if(! isset($r[$k])) $r[$k] = $v;<br /> elseif($r[$k]['time'] < $v['time']) $r[$k] = $v;<br /> elseif($r[$k]['time'] == $v['time']) unset($r[$k]);<br />}<br />ksort($r);<br />print_r($r);
Array<br />(<br /> [2] => Array<br /> (<br /> [id] => 2<br /> [time] => 55<br /> [neirong] => www<br /> )<br /><br /> [3] => Array<br /> (<br /> [id] => 3<br /> [time] => 555<br /> )<br /><br /> [4] => Array<br /> (<br /> [id] => 4<br /> [time] => 555<br /> [neirong] => www<br /> )<br /><br /> [5] => Array<br /> (<br /> [id] => 5<br /> [time] => 555<br /> [neirong] => www<br /> )<br /><br />)<br /><br />