How to put an array like this over
["Q"] = = Array (4) {[0] = = Array (one) {["id"] + = string (1) "1", ["k"] = string (1) "Q"} [1] = = Array (one) {["id"] = + string (1) "2", ["k"] + = string (1) "H"} [2] = arr Ay (one) {["id"] + = string (1) "3", ["k"] + = string (1) "V"} [3] = = Array (11) {[" id "] = = string (1)" 4 ", [" k "] = + string (1)" V "}}[" V "] = = Array (4) {[0] = = Array (11) { ["id"] + = string (1) "1", ["k"] = + string (1) "Q"} [1] = = Array (one) {["id"] + = string ( 1) "2", ["k"] + = string (1) "H"} [2] = = Array (one) {["id"] + = string (1) "3", ["k"] = = St Ring (1) "V"} [3] = = Array (one) {["id"] + = string (1) "4", ["k"] = = string (1) "V" }}["H"] + = Array (4) {[0] = = Array (one) {["id"] + = string (1) "1", ["k"] = + string (1) "Q" } [1] = arrAy (one) {["id"] + = string (1) "2", ["k"] + = string (1) "H"} [2] = = Array (one) {["ID "] = = string (1)" 3 ", [" k "] + = string (1)" V "} [3] = = Array (one) {[" id "] = = string (1)" 4 ", [" k "] + = string (1)" V "}}
Filter it into this.
["Q"] => array(1) { [0] => array(11) { ["id"] => string(1) "1" ["k"] => string(1) "Q" }}["V"] => array(2) { [0] => array(11) { ["id"] => string(1) "3" ["k"] => string(1) "V" } [1] => array(11) { ["id"] => string(1) "4" ["k"] => string(1) "V" }}["H"] => array(1) { [0] => array(11) { ["id"] => string(1) "2" ["k"] => string(1) "H" }}
Reply content:
How to put an array like this over
["Q"] = = Array (4) {[0] = = Array (one) {["id"] + = string (1) "1", ["k"] = string (1) "Q"} [1] = = Array (one) {["id"] = + string (1) "2", ["k"] + = string (1) "H"} [2] = arr Ay (one) {["id"] + = string (1) "3", ["k"] + = string (1) "V"} [3] = = Array (11) {[" id "] = = string (1)" 4 ", [" k "] = + string (1)" V "}}[" V "] = = Array (4) {[0] = = Array (11) { ["id"] + = string (1) "1", ["k"] = + string (1) "Q"} [1] = = Array (one) {["id"] + = string ( 1) "2", ["k"] + = string (1) "H"} [2] = = Array (one) {["id"] + = string (1) "3", ["k"] = = St Ring (1) "V"} [3] = = Array (one) {["id"] + = string (1) "4", ["k"] = = string (1) "V" }}["H"] + = Array (4) {[0] = = Array (one) {["id"] + = string (1) "1", ["k"] = + string (1) "Q" } [1] = arrAy (one) {["id"] + = string (1) "2", ["k"] + = string (1) "H"} [2] = = Array (one) {["ID "] = = string (1)" 3 ", [" k "] + = string (1)" V "} [3] = = Array (one) {[" id "] = = string (1)" 4 ", [" k "] + = string (1)" V "}}
Filter it into this.
["Q"] => array(1) { [0] => array(11) { ["id"] => string(1) "1" ["k"] => string(1) "Q" }}["V"] => array(2) { [0] => array(11) { ["id"] => string(1) "3" ["k"] => string(1) "V" } [1] => array(11) { ["id"] => string(1) "4" ["k"] => string(1) "V" }}["H"] => array(1) { [0] => array(11) { ["id"] => string(1) "2" ["k"] => string(1) "H" }}
!--? Php$arr = Array (' Q ' =-->array (' id ' =>1, ' k ' = ' Q '), Array (' ID ' =>2, ' k ' = ' H '), array (' ID ' =>3, ' k ' = = ') V '), array (' ID ' =>4, ' k ' = ' V '),), ' V ' =&G T;array (Array (' ID ' =>1, ' k ' = ' = ' Q '), array (' ID ' =>2, ' k ' = ' H '), array (' ID ' =>3, ' k ' = ' V '), Array ( ' id ' =>4, ' k ' = ' V '), ' H ' =>array (array (' ID ' =>1, ' K ' = = ' Q '), array (' ID ' =>2, ' k ' = ' H '), array (' ID ' =& Gt;3, ' k ' = ' V '), array (' ID ' =>4, ' k ' = ' V '), ); Echo '
';print_r($arr);$new_arr = array();foreach($arr as $key=>$val) { foreach($val as $k=>$v) { if($key == $v['k']) { $new_arr[$key][] = $v; } }}echo '';print_r($new_arr);
Array_filter ($arr, fun);
Fun inside with the array of key go and K judge, not equal to the unset off
$keys = array_keys($arr);$newArr = array();$i = 0;foreach ($arr as $key => $value) { $newArr[$key] = array_filter($value, function ($val) { GLOBAL $keys; GLOBAL $i; return $val["k"] == $keys[$i]; }); $i++;}