元の配列は
$arr = array( array( 'id' => '1', 'name' => 'a', 'project' => '1', ), array( 'id' => '2', 'name' => 'b', 'project' => '3', ), array( 'id' => '3', 'name' => 'c', 'project' => '2', ), array( 'id' => '4', 'name' => 'd', 'project' => '1', ), );
$arr1 = array( array( 'id' => '1', 'name' => 'a', 'project' => '1', ), array( 'id' => '4', 'name' => 'd', 'project' => '1', ), ); $arr2 = array( array( 'id' => '2', 'name' => 'b', 'project' => '3', ), ); $arr3 = array( array( 'id' => '3', 'name' => 'c', 'project' => '2', ), );
ディスカッションへの返信 (解決策)
$arr = array( array( 'id' => '1', 'name' => 'a', 'project' => '1', ), array( 'id' => '2', 'name' => 'b', 'project' => '3', ), array( 'id' => '3', 'name' => 'c', 'project' => '2', ), array( 'id' => '4', 'name' => 'd', 'project' => '1', ), );foreach($arr as $v) $r['arr' . $v['project']][] = $v;extract($r);print_r($arr1);
Array( [0] => Array ( [id] => 1 [name] => a [project] => 1 ) [1] => Array ( [id] => 4 [name] => d [project] => 1 ))