概要
閲覧数:975
投稿日:2014-10-08
更新日:2014-10-08
「Array a b」より「Array c」を作成
コード
$a = array( "3" => 3, "42" => 15, "4" => 22, "88" => 6, ); $b = array( "0" => array( "id" => 42, "area" => "東京", ), "1" => array( "id" => 88, "area" => "大阪", ) ); print_r($a); print_r($b); $c = array(); for($i = 0;$i < count($b);$i++){ $c[$b[$i]['id']]['num'] = $a[$b[$i]['id']]; $c[$b[$i]['id']]['area'] = $b[$i]['area']; } print_r($c); foreach($c as $key => $val){ echo $key." "; }
結果
Array ( [3] => 3 [42] => 15 [4] => 22 [88] => 6 ) Array ( [0] => Array ( [id] => 42 [area] => 東京 ) [1] => Array ( [id] => 88 [area] => 大阪 ) ) Array ( [42] => Array ( [num] => 15 [area] => 東京 ) [88] => Array ( [num] => 6 [area] => 大阪 ) ) 42 88