> 백엔드 개발 > PHP 튜토리얼 > php数组如何转化成如下数组...

php数组如何转化成如下数组...

WBOY
풀어 주다: 2016-06-06 20:09:57
원래의
801명이 탐색했습니다.

<code>Array
(
    [0] => Array
        (
            [ce_id] => 1
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 123
            [ce_img] => /upload/certification/1_1459410425_4041.png
            [ce_create_at] => 2016-03-31 15:47:05
            [ce_update_at] => 2016-03-31 15:47:05
            [cn_id] => 1
            [cn_certification_name] => 学历证明
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

    [1] => Array
        (
            [ce_id] => 2
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 正面
            [ce_img] => /upload/certification/1_1459413288_5730.png
            [ce_create_at] => 2016-03-31 16:34:48
            [ce_update_at] => 2016-03-31 16:34:48
            [cn_id] => 1
            [cn_certification_name] => 学历证明
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

    [2] => Array
        (
            [ce_id] => 3
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 正面
            [ce_img] => /upload/certification/1_1459413934_4724.png
            [ce_create_at] => 2016-03-31 16:45:34
            [ce_update_at] => 2016-03-31 16:45:34
            [cn_id] => 1
            [cn_certification_name] => 学历证明
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

    [3] => Array
        (
            [ce_id] => 4
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 正面
            [ce_img] => /upload/certification/1_1459414535_2607.png
            [ce_create_at] => 2016-03-31 16:55:35
            [ce_update_at] => 2016-03-31 16:55:35
            [cn_id] => 1
            [cn_certification_name] => 学历证明a
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

)
</code>
로그인 후 복사
로그인 후 복사

这正数组怎么变成
cn_certification_name为键,cn_certification_name这字段相同的值就放在这字段下面。。
如:

<code>array(2) {
  ["学历证明"]=>
  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_1459410425_4041.png"
      ["ce_create_at"]=>
      string(19) "2016-03-31 15:47:05"
      ["ce_update_at"]=>
      string(19) "2016-03-31 15:47:05"
      ["cn_id"]=>
      string(1) "1"
      ["cn_certification_name"]=>
      string(12) "学历证明"
      ["cn_create_at"]=>
      string(19) "2016-03-31 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) "正面"
      ["ce_img"]=>
      string(43) "/upload/certification/1_1459413288_5730.png"
      ["ce_create_at"]=>
      string(19) "2016-03-31 16:34:48"
      ["ce_update_at"]=>
      string(19) "2016-03-31 16:34:48"
      ["cn_id"]=>
      string(1) "1"
      ["cn_certification_name"]=>
      string(12) "学历证明"
      ["cn_create_at"]=>
      string(19) "2016-03-31 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) "正面"
      ["ce_img"]=>
      string(43) "/upload/certification/1_1459413934_4724.png"
      ["ce_create_at"]=>
      string(19) "2016-03-31 16:45:34"
      ["ce_update_at"]=>
      string(19) "2016-03-31 16:45:34"
      ["cn_id"]=>
      string(1) "1"
      ["cn_certification_name"]=>
      string(12) "学历证明"
      ["cn_create_at"]=>
      string(19) "2016-03-31 10:54:02"
      ["cn_create_user_id"]=>
      NULL
    }
  }
  ["学历证明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) "2016-04-01 11:27:04"
      ["cn_id"]=>
      string(1) "3"
      ["cn_certification_name"]=>
      string(13) "学历证明a"
      ["cn_create_at"]=>
      string(19) "2016-04-01 11:26:11"
      ["cn_create_user_id"]=>
      NULL
    }
  }
}
</code>
로그인 후 복사
로그인 후 복사

回复内容:

<code>Array
(
    [0] => Array
        (
            [ce_id] => 1
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 123
            [ce_img] => /upload/certification/1_1459410425_4041.png
            [ce_create_at] => 2016-03-31 15:47:05
            [ce_update_at] => 2016-03-31 15:47:05
            [cn_id] => 1
            [cn_certification_name] => 学历证明
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

    [1] => Array
        (
            [ce_id] => 2
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 正面
            [ce_img] => /upload/certification/1_1459413288_5730.png
            [ce_create_at] => 2016-03-31 16:34:48
            [ce_update_at] => 2016-03-31 16:34:48
            [cn_id] => 1
            [cn_certification_name] => 学历证明
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

    [2] => Array
        (
            [ce_id] => 3
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 正面
            [ce_img] => /upload/certification/1_1459413934_4724.png
            [ce_create_at] => 2016-03-31 16:45:34
            [ce_update_at] => 2016-03-31 16:45:34
            [cn_id] => 1
            [cn_certification_name] => 学历证明
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

    [3] => Array
        (
            [ce_id] => 4
            [ce_category_id] => 1
            [ce_user_id] => 10
            [ce_remark] => 正面
            [ce_img] => /upload/certification/1_1459414535_2607.png
            [ce_create_at] => 2016-03-31 16:55:35
            [ce_update_at] => 2016-03-31 16:55:35
            [cn_id] => 1
            [cn_certification_name] => 学历证明a
            [cn_create_at] => 2016-03-31 10:54:02
            [cn_create_user_id] => 
        )

)
</code>
로그인 후 복사
로그인 후 복사

这正数组怎么变成
cn_certification_name为键,cn_certification_name这字段相同的值就放在这字段下面。。
如:

<code>array(2) {
  ["学历证明"]=>
  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_1459410425_4041.png"
      ["ce_create_at"]=>
      string(19) "2016-03-31 15:47:05"
      ["ce_update_at"]=>
      string(19) "2016-03-31 15:47:05"
      ["cn_id"]=>
      string(1) "1"
      ["cn_certification_name"]=>
      string(12) "学历证明"
      ["cn_create_at"]=>
      string(19) "2016-03-31 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) "正面"
      ["ce_img"]=>
      string(43) "/upload/certification/1_1459413288_5730.png"
      ["ce_create_at"]=>
      string(19) "2016-03-31 16:34:48"
      ["ce_update_at"]=>
      string(19) "2016-03-31 16:34:48"
      ["cn_id"]=>
      string(1) "1"
      ["cn_certification_name"]=>
      string(12) "学历证明"
      ["cn_create_at"]=>
      string(19) "2016-03-31 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) "正面"
      ["ce_img"]=>
      string(43) "/upload/certification/1_1459413934_4724.png"
      ["ce_create_at"]=>
      string(19) "2016-03-31 16:45:34"
      ["ce_update_at"]=>
      string(19) "2016-03-31 16:45:34"
      ["cn_id"]=>
      string(1) "1"
      ["cn_certification_name"]=>
      string(12) "学历证明"
      ["cn_create_at"]=>
      string(19) "2016-03-31 10:54:02"
      ["cn_create_user_id"]=>
      NULL
    }
  }
  ["学历证明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) "2016-04-01 11:27:04"
      ["cn_id"]=>
      string(1) "3"
      ["cn_certification_name"]=>
      string(13) "学历证明a"
      ["cn_create_at"]=>
      string(19) "2016-04-01 11:26:11"
      ["cn_create_user_id"]=>
      NULL
    }
  }
}
</code>
로그인 후 복사
로그인 후 복사

这应该是你想要的意思了

<code>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;
    }</code>
로그인 후 복사

<code class="php">// 来个简单的
$res = [];
foreach($arr as $v){
     $res[$v['cn_certification_name']][] = $v;
}</code>
로그인 후 복사

你是要按照字段cn_certification_name排序吗?是这意思?

你是想实现二维数组转多维吧 比如爹下面有儿子儿子下面有儿子 然后这条关系都挂在同同一条数据下面

foreach($ARR as $VALUA) 这个

(strval)$;

typeof( )

用这三个函数,做不到吗?

관련 라벨:
php
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿