PHP combines an array with the same fields in a two-dimensional array. tutorial on two-dimensional array _ PHP

Source: Internet
Author: User
PHP combines an array with the same fields of a two-dimensional array, a two-dimensional array. PHP combines an array with the same fields in a two-dimensional array. This article describes how PHP combines an array with the same fields in a two-dimensional array. PHP combines an array with the same fields in a two-dimensional array.

This example describes how PHP combines an array with the same fields in a two-dimensional array. 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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.