How to convert php arrays into the following arrays...

Source: Internet
Author: User
{Code...}: How does the positive array change to cn_certification_name as the key? The same value of cn_certification_name is placed under this field .. Example: {code ...}
Array ([0] => Array ([ce_id] => 1 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => 123 [ce_img] =>/upload /certification [ce_create_at] => 15:47:05 [ce_update_at] => 15:47:05 [cn_id] => 1 [cn_certification_name] => diploma certificate [cn_create_at] => 10:54:02 [certification] =>) [1] => Array ([ce_id] => 2 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => front [ce_img] =>/upload/certification /certificate [ce_create_at] => 16:34:48 [ce_update_at] => 16:34:48 [cn_id] => 1 [cn_certification_name] => proof of education [cn_create_at] => 10:54:02 [cn_create_user_id] = >) [2] => Array ([ce_id] => 3 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => front [ce_img] =>/upload/certification /certificate [ce_create_at] => 16:45:34 [ce_update_at] => 16:45:34 [cn_id] => 1 [cn_certification_name] => proof of education [cn_create_at] => 10:54:02 [cn_create_user_id] = >) [3] => Array ([ce_id] => 4 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => front [ce_img] =>/upload/certification /certificate [ce_create_at] => 16:55:35 [ce_update_at] => 16:55:35 [cn_id] => 1 [cn_certification_name] => diploma a [cn_create_at] => 10:54:02 [cn_create_user_id] => ))

How to convert the positive array
Tocn_certification_nameIs the key,cn_certification_nameThe same value of this field is placed under this field ..
For example:

Array (2) {["diploma certificate"] => array (4) {[0] => array (11) {["ce_id"] => string (1) "1" ["ce_category_id"] => string (1) "1" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (3) "123" ["ce_img"] => string (43) "/upload/certification/1_14591_1__4041.png" ["ce_create_at"] => string (19) "15:47:05" ["ce_update_at"] => string (19) "15:47:05" ["cn_id"] => string (1) "1" ["cn_certification_name"] => string (12) "Certification" ["cn_create_at"] => string (19) "10:54:02" ["cn_create_user_id"] => NULL} [1] => array (11) {["ce_id"] => string (1) "2" ["ce_category_id"] => string (1) "1" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (6) "Front" ["ce_img"] => string (43) "/upload/certification/1_1459413288_5730.png" ["ce_create_at"] => string (19) "16:34:48" ["ce_update_at"] => string (19) "16:34:48" ["cn_id"] => string (1) "1" ["cn_certification_name"] => string (12) "Certification" ["cn_create_at"] => string (19) "10:54:02" ["cn_create_user_id"] => NULL} [2] => array (11) {["ce_id"] => string (1) "3" ["ce_category_id"] => string (1) "1" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (6) "Front" ["ce_img"] => string (43) "/upload/certification/4151459413934_4724.png" ["ce_create_at"] => string (19) "16:45:34" ["ce_update_at"] => string (19) "16:45:34" ["cn_id"] => string (1) "1" ["cn_certification_name"] => string (12) "diploma" ["cn_create_at"] => string (19) "10:54:02" ["cn_create_user_id"] => NULL} ["diploma a"] => array (1) {[0] => array (11) {["ce_id"] => string (2) "23" ["ce_category_id"] => string (1) "3" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (3) "789" ["ce_img"] => string (43) "/upload/certification/3_1459481224_8477.png" ["ce_create_at"] => string (19) "2016-04-01 11:27:04" ["ce_update_at"] => string (19) "11:27:04" ["cn_id"] => string (1) "3" ["cn_certification_name"] => string (13) "certification a" ["cn_create_at"] => string (19) "11:26:11" ["cn_create_user_id"] => NULL }}}

Reply content:
Array ([0] => Array ([ce_id] => 1 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => 123 [ce_img] =>/upload /certification [ce_create_at] => 15:47:05 [ce_update_at] => 15:47:05 [cn_id] => 1 [cn_certification_name] => diploma certificate [cn_create_at] => 10:54:02 [certification] =>) [1] => Array ([ce_id] => 2 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => front [ce_img] =>/upload/certification /certificate [ce_create_at] => 16:34:48 [ce_update_at] => 16:34:48 [cn_id] => 1 [cn_certification_name] => proof of education [cn_create_at] => 10:54:02 [cn_create_user_id] = >) [2] => Array ([ce_id] => 3 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => front [ce_img] =>/upload/certification /certificate [ce_create_at] => 16:45:34 [ce_update_at] => 16:45:34 [cn_id] => 1 [cn_certification_name] => proof of education [cn_create_at] => 10:54:02 [cn_create_user_id] = >) [3] => Array ([ce_id] => 4 [ce_category_id] => 1 [ce_user_id] => 10 [ce_remark] => front [ce_img] =>/upload/certification /certificate [ce_create_at] => 16:55:35 [ce_update_at] => 16:55:35 [cn_id] => 1 [cn_certification_name] => diploma a [cn_create_at] => 10:54:02 [cn_create_user_id] => ))

How to convert the positive array
Tocn_certification_nameIs the key,cn_certification_nameThe same value of this field is placed under this field ..
For example:

Array (2) {["diploma certificate"] => array (4) {[0] => array (11) {["ce_id"] => string (1) "1" ["ce_category_id"] => string (1) "1" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (3) "123" ["ce_img"] => string (43) "/upload/certification/1_14591_1__4041.png" ["ce_create_at"] => string (19) "15:47:05" ["ce_update_at"] => string (19) "15:47:05" ["cn_id"] => string (1) "1" ["cn_certification_name"] => string (12) "Certification" ["cn_create_at"] => string (19) "10:54:02" ["cn_create_user_id"] => NULL} [1] => array (11) {["ce_id"] => string (1) "2" ["ce_category_id"] => string (1) "1" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (6) "Front" ["ce_img"] => string (43) "/upload/certification/1_1459413288_5730.png" ["ce_create_at"] => string (19) "16:34:48" ["ce_update_at"] => string (19) "16:34:48" ["cn_id"] => string (1) "1" ["cn_certification_name"] => string (12) "Certification" ["cn_create_at"] => string (19) "10:54:02" ["cn_create_user_id"] => NULL} [2] => array (11) {["ce_id"] => string (1) "3" ["ce_category_id"] => string (1) "1" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (6) "Front" ["ce_img"] => string (43) "/upload/certification/4151459413934_4724.png" ["ce_create_at"] => string (19) "16:45:34" ["ce_update_at"] => string (19) "16:45:34" ["cn_id"] => string (1) "1" ["cn_certification_name"] => string (12) "diploma" ["cn_create_at"] => string (19) "10:54:02" ["cn_create_user_id"] => NULL} ["diploma a"] => array (1) {[0] => array (11) {["ce_id"] => string (2) "23" ["ce_category_id"] => string (1) "3" ["ce_user_id"] => string (2) "10" ["ce_remark"] => string (3) "789" ["ce_img"] => string (43) "/upload/certification/3_1459481224_8477.png" ["ce_create_at"] => string (19) "2016-04-01 11:27:04" ["ce_update_at"] => string (19) "11:27:04" ["cn_id"] => string (1) "3" ["cn_certification_name"] => string (13) "certification a" ["cn_create_at"] => string (19) "11:26:11" ["cn_create_user_id"] => NULL }}}

This is what you want.

function changeArray($arr){        $newArr = $keyTmp =  array();        foreach($arr as $val){            array_push($keyTmp, $val['cn_certification_name']);        }        unset($val);        $keyTmp = array_unique($keyTmp);        foreach($arr as $val){            foreach($keyTmp as $tmpVal){                if($val['cn_certification_name'] == $tmpVal){                    $newArr[$tmpVal][] = $val;                }            }        }        return $newArr;    }

// A simple $ res = []; foreach ($ arr as $ v) {$ res [$ v ['cn _ certif_name _name '] [] = $ v ;}

Do you want to sort by cn_certification_name? That means?

You want to convert a two-dimensional array to multiple dimensions. For example, if you have a son under your father and a son under your son, then the relationship is hashed under the same data.

Foreach ($ ARR as $ VALUA)

(Strval) $;

Typeof ()

Can't I use these three functions?

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.