ホームページ >バックエンド開発 >PHPチュートリアル >PHPは2つの2次元配列を結合します
PHP は、時間順にソートされた 2 つの 2 次元配列
をマージします
<br /> <br /> $data1 = array(<br /> <br /> [0] => array(<br /> times => '2012-10-10',<br /> type =>0,<br /> num =>100<br /> ),<br /> <br /> [1] => array(<br /> times => '2012-10-11',<br /> type =>0,<br /> num =>103<br /> ),<br /> <br /> ....<br /> <br /> )<br /> <br /> $data2 = array(<br /> <br /> [0] => array(<br /> times => '2012-10-10',<br /> type =>1,<br /> num =>400<br /> ),<br /> <br /> [1] => array(<br /> times => '2012-10-11',<br /> type =>1,<br /> num =>403<br /> ),<br /> <br /> ....<br /> <br /> )<br /> <br />
<br /> $data = array(<br /> <br /> [0] => array(<br /> times => '2012-10-10',<br /> type =>0,<br /> num =>100<br /> type =>1,<br /> num =>400<br /> ),<br /> <br /> [1] => array(<br /> times => '2012-10-11',<br /> type =>0,<br /> num =>103<br /> type =>1,<br /> num =>403<br /> ),<br /> <br /> ....<br /> <br /> )<br />
<br> $date=array(array("time"=>"2012-11-10","type0"=>0,"num0"=>100),array("time"=>"2012-11 -11","type0"=>0,"num0"=>103));<br> $date1=array(array("time"=>"2012-11-10","type1"=>1,"num1"=>105),array("time"=>"2012-11 -11","type1"=>1,"num1"=>120));<br> $cnt=count($date);<br> for($i=0;$i $date2[$i]=array_merge($date[$i],$date1[$i]);<br> }<br> echo "e03b848252eb9375d56be284e690e873";<br> print_r($date);<br> print_r($date1);<br> print_r($date2);<br> echo "bc5574f69a0cba105bc93bd3dc13c4ec";<br> //結果は以下の通りです<br> 配列<br> (<br> [0] => 配列<br> (<br> [時刻] = & gt; 2012-11-10 <br> [タイプ0] = & GT 0 <br> [num0] => )<br> <br><div class="clear"></div>