This article mainly introduces how PHP combines an array with the same fields of a two-dimensional array, and related techniques related to PHP multi-dimensional array operations, for more information about how PHP combines an array with the same field in a two-dimensional array, see the example in this article. We will share this with you for your reference. The details are as follows:
Example:
Array (3) {[0] => array (16) {["id"] => string (2) "42" ["uid"] => string (2) "14" ["euid"] => string (2) "56" ["did"] => string (1) "1" ["nid"] => string (1) "0" ["phonetime"] => string (10) "1443927600" ["createtime"] => string (10) "1443880619" ["type"] => string (1) "3" ["status"] => string (1) "0" ["atype"] => string (1) "1" ["mtype"] => string (1) "2" ["endtime"] => string (1) "0" ["time"] => string (10) "October 04" ["date"] => string (6) "Sunday" ["uname"] => NULL ["album"] => string (0) ""} [1] => array (16) {["id"] => string (2) "40" ["uid"] => string (2) "14" ["euid"] => string (2) "56" ["did"] => string (1) "1" ["nid"] => string (1) "0" ["phonetime"] => string (10) "1444359600" ["createtime"] => string (10) 1444268595 "[" type "] => string (1)" 3 "[" status "] => string (1) "0" ["atype"] => string (1) "1" ["mtype"] => string (1) "2" ["endtime"] => string (1) "0" ["time"] => string (10) "October 09" ["date"] => string (6) "Friday" ["uname"] => NULL ["album"] => string (0) ""} [2] => array (16) {["id"] => string (2) "43" ["uid"] => string (1) "2" ["euid"] => string (2) "56" ["did"] => string (1) "1" ["nid"] => string (1) "0" ["phonetime"] => string (10) "1444359620" ["createtime"] => string (10) "1444268595" ["type"] => string (1) "3" ["status"] => string (1) "0" ["atype"] => string (1) "1" ["mtype"] => string (1) "2" ["endtime"] => string (1) "0" ["time"] => string (10) "October 09" ["date"] => string (6) "Friday" ["uname"] => NULL ["album"] => string (0 )""}}
Now we want to merge the elements in the two-dimensional array with the same time to the same array. The expected results are as follows:
Array (2) {["October 04"] => array (1) {[0] => array (16) {["id"] => string (2) "42" ["uid"] => string (2) "14" ["euid"] => string (2) "56" ["did"] => string (1) "1" ["nid"] => string (1) "0" ["phonetime"] => string (10) "1443927600" ["createtime"] => string (10) 1443880619 "[" type "] => string (1)" 3 "[" status "] => string (1) "0" ["atype"] => string (1) "1" ["mtype"] => string (1) "2" ["endtime"] => string (1) "0" ["time"] => string (10) "October 04" ["date"] => string (6) "Sunday" ["uname"] => NULL ["album"] => string (0) ""} ["October 09"] => array (2) {[0] => array (16) {["id"] => string (2) "40" ["uid"] => string (2) "14" ["euid"] => string (2) "56" ["did"] => string (1) "1" ["nid"] => string (1) "0" ["phonetime"] => string (10) "1444359600" ["createtime"] => string (10) 1444268595 "[" type "] => string (1)" 3 "[" status "] => string (1) "0" ["atype"] => string (1) "1" ["mtype"] => string (1) "2" ["endtime"] => string (1) "0" ["time"] => string (10) "October 09" ["date"] => string (6) "Friday" ["uname"] => NULL ["album"] => string (0) ""} [1] => array (16) {["id"] => string (2) "43" ["uid"] => string (1) "2" ["euid"] => string (2) "56" ["did"] => string (1) "1" ["nid"] => string (1) "0" ["phonetime"] => string (10) "1444359620" ["createtime"] => string (10) "1444268595" ["type"] => string (1) "3" ["status"] => string (1) "0" ["atype"] => string (1) "1" ["mtype"] => string (1) "2" ["endtime"] => string (1) "0" ["time"] => string (10) "October 09" ["date"] => string (6) "Friday" ["uname"] => NULL ["album"] => string (0 )""}}}
So... The code is very simple, not as complicated as imagined, and the desired result is a three-dimensional array.
$ Result is the original two-dimensional array.
$ Res = array (); // expected result foreach ($ result as $ k => $ v) {$ res [$ v ['Time'] [] = $ v ;}
The above is the PHP method to combine an array with the same fields in a two-dimensional array _ php skills. For more information, see The PHP Chinese website (www.php1.cn )!