The original array is similar
$arr = 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 ', ), );
I want to make multiple arrays based on the same nature of project, such as the following results
$arr 1 = Array ( ' id ' = ' 1 ', ' name ' = ' a ', ' project ' = ' 1 ', ), array ( ' id ' = ' 4 ', ' name ' = ' d ', ' project ' = ' 1 ', ) ; $arr 2 = Array ( ' id ' = ' 2 ', ' name ' = ' B ' , ' Project ' = ' 3 ', ), ); $arr 3 = Array ( ' id ' = ' 3 ', ' name ' = ' C ' , ' Project ' = ' 2 ', ), );
Ask for help, I have a train of thought, want to let project order, and then loop to determine whether the next Val[project] is the same as the previous, the new array is formed.
But there are other ways to do it.
Reply to discussion (solution)
$arr = 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);p Rint_r ($arr 1);
Array ( [0] = = Array ( [id] = 1 [name] + a [Project] = 1 ) [1] = = Array ( [id] = 4 [name] + D [Project] = 1 ))
Other self-authentication
Extract () When do you usually use
Thank you, for the first time know $r[' arr '. $v [' project ']][] = $v; You can also let the array to find the corresponding location, in fact, this sentence to reach the results I want, I kind of way I feel tired
Extract () looked at it before, roughly giving Val directly to the variable in the $+key name.