php 两个二维数组合并,根据某个字段去重并排序

<?php
/**
 * Created by PhpStorm.
 * User: zhangheg
 * Date: 2018/7/22
 * Time: 20:48
 */
$a = [
    ['value'=>0,'create_time'=>'2008-08-7-06'],
    ['value'=>0,'create_time'=>'2008-08-7-07'],
    ['value'=>0,'create_time'=>'2008-08-7-08'],
    ['value'=>0,'create_time'=>'2008-08-7-09'],
    ['value'=>0,'create_time'=>'2008-08-7-10']
];
$b= [
    ['value'=>1,'create_time'=>'2008-08-7-06'],
    ['value'=>10,'create_time'=>'2008-08-7-09']
];
$c = array_merge($a,$b);
$narr = arr($c,$b);
var_dump(sortArr($narr));
function arr($c,$b){
    foreach ($c as $key=>&$v){
        foreach ($b as &$val){
            if($val['create_time'] == $v['create_time'] && $v['value'] == 0){
                unset($c[$key]);
            }
        }

        //判断日期b存在并且0删除
    }
    return $c;
}

function sortArr($c){
    $sort = array_column($c, 'create_time');

    array_multisort($sort, SORT_ASC, $c);
    return $c;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注