1
$arr1=array(
    array(
        "name"=> "张三",
        "qty"=> "4"
    ),
    array(
        "name"=> "李四",
        "qty"=>"10"
    ),
    array(
        "name"=> "李四",
        "qty"=> "5"
    )
);

将name 相同的数组合并,并将数量qty相加。

//声明中间数组
$temp = [];
//声明结果数组
$final = [];
foreach ($arr1 as $value) {
    if (isset($temp[$value['name']])) {
        //name存在追加数量
        $temp[$value['name']] = $temp[$value['name']] + (float)$value['qty'];
        } else {
        //name不存在加入数组
        $temp[$value['name']] = (float)$value['qty'];
        }
}
print_r($temp);
//结果
Array
(
    [张三] => 4
    [李四] => 15
)
//恢复到原来的二维
foreach($temp as $key=>$value){
    $final[]=['name'=>$key,'qty'=>$value];
}
print_r($final);
//结果
Array
(
    [0] => Array
        (
            [name] => 张三
            [qty] => 4
        )

    [1] => Array
        (
            [name] => 李四
            [qty] => 15
        )

)

Donne
694 声望25 粉丝

知其然,知其所以然。