javascript - php array merging problem
我想大声告诉你
我想大声告诉你 2017-05-16 13:14:34
0
2
623

Array
(

[村西] => Array
    (
        [0] => Array
            (
                [headimg] =>'头像'
                [info] => 村西                
                [product_name] =>产品1
            )

        [1] => Array
            (   
                [headimg] =>'头像'        
                [info] => 村西             
                [product_name] => 产品2
            )

    )

[村东] => Array
    (
        [0] => Array
            (   
                [headimg] =>'头像'               
                [info] => 村东
                [product_name] => 产品3
            )

        [1] => Array
            (   
                [headimg] =>'头像'                
                [info] => 村东
                [product_name] => 产品4
            )
        [2] => Array
            (   
                [headimg] =>'头像'                
                [info] => 村东
                [product_name] => 产品5
            )

    )

[小邢庄村口] => Array
    (
        [0] => Array
            (   
                [headimg] =>'头像'             
                [info] => 小邢庄村口                  
                [product_name] => 产品6
            )

    )

Now the info has been merged into an array, that is, 'Village East' and 'Village West'. . Now I want to merge product_names in the same info together.
For example, 'Product 1' and 'Product 2' in Cunxi are merged together in the form of an array.

In addition, the health value of headimg should be retained
Thank you very much

我想大声告诉你
我想大声告诉你

reply all(2)
Peter_Zhu
    $data = array();
    foreach ($a as $k=>$v) {

        foreach($v as $key=>$val){
            if ($val['name'] == $k){
                $data[$k][$key]['product_name'] = $val['product_name'];
                $data[$k][$key]['head'] = $val['head'];
            }
        }
    }
PHPzhong
<?php
$result=array();
foreach($arr as $k=>$v){
    foreach($v as $item){
        $result[$k][]=$item['product_name'];
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template