PHP-将数组的子元素组合成数组


PHP- Combine child element of an array into an array

我有这样的数据
数组

   数组(3) {      [0]=>      数组(5) {        ["cate_title"]=>        字符串(30) "打印机线 - 与日期四舍五入"        ["attr_id"]=>        字符串(2) "15"        ["attr"]=>        字符串(6) "阿斯达斯"        ["选项"]=>        字符串(6) "阿斯达斯"        ["data_name"]=>        数组(0) {        }      }      [1]=>      数组(5) {        ["cate_title"]=>        字符串(1) "W"        ["attr_id"]=>        字符串(2) "14"        ["attr"]=>        字符串(4) "阿斯达"        ["选项"]=>        字符串(5) "SDASD"        ["data_name"]=>        数组(0) {        }      }      [2]=>      数组(5) {        ["cate_title"]=>        字符串(1) "W"        ["attr_id"]=>        字符串(2) "13"        ["attr"]=>        字符串(3) "AAA"        ["选项"]=>        字符串(8) "复选框"        ["data_name"]=>        数组(1) {          [0]=>          字符串(3) "bbb"        }      }    }    

我想像这样将具有相同cate_title = w的 2 个 elenment 组合成 1 个数组

<pre>
array(3) {
  [0]=>
  array(5) {
    ["cate_title"]=>
    string(30) "Printer Line - Round With Date"
    ["attr_id"]=>
    string(2) "15"
    ["attr"]=>
    string(6) "asdasd"
    ["option"]=>
    string(6) "asdasd"
    ["data_name"]=>
    array(0) {
    }
  }
  [1]=>  
  array(2) {
    ["cate_title"]=>string(1) "w"  
      ["data-child"]=>array(2){
        [0]=>array {
        ["attr_id"]=>string(2) "14"
        ["attr"]=>string(4) "asda"
        ["option"]=>string(5) "sdasd"
        ["data_name"]=> array(0) {    }
        }
        [1]=>array {
        ["attr_id"]=>string(2) "13"
        ["attr"]=>string(4) "aaa"
        ["option"]=>string(5) "checkbox"
        ["data_name"]=> array(1) {
            [0]=>
            string(3) "bbb"
            }    
        }
    }
  }
</pre>

请帮助我,我已经到处搜索但仍然没有答案

这是解决方案

<?php
    foreach($arr as $v){
        $newArr[$v["cate_title"]][] = $v;
    }
    var_dump(array_values($newArr));
?>