PHP根据数组的值分组

PHP根据数组的值分组,php array中没有自带这个函数但是很常用,今天写了出来记录一下。

代码:

$_array = array(
        array(1,11,'2016-05-18'),
        array(2,11,'2016-05-18'),
        array(3,22,'2016-05-18'),
        array(4,22,'2016-05-18'),
        array(5,33,'2016-05-19'),
        array(6,33,'2016-05-19'),
        array(7,44,'2016-05-19'),
        array(8,44,'2016-05-19'),
        array(9,55,'2016-05-20'),
        array(10,55,'2016-05-20'),
    );
    var_dump(array_val_chunk($_array));

function array_val_chunk($array){
        $result = [];
        foreach ($array as $key => $value) {
            $result[$value[1].$value[2]][] = $value;
        }
        $ret = [];
        //这里把简直转成了数字的,方便同意处理
        foreach ($result as $key => $value) {
            array_push($ret, $value);
        }
        return $ret;
    }

上一篇:Zookeeper安装和配置


下一篇:Installing Ruby 1.9.3 on Ubuntu 12.04 Precise Pengolin (without RVM)