[1].[代码] array_column 跳至 [1]

    //处理记录集(php5.5内置)
    static function array_column($data,$key='id',$column=null){

        $buffer=null;

        if ($column) {
            //k=>v
            if (strpos($column,',') === false) {
                foreach ($data as $value) {
                    $buffer[$value[$key]]=$value[$column];
                }
                return $buffer;
            }

            //k=arr
            $field=explode(',',$column);
            foreach ($data as $value) {
                $id=$value[$key];
                array_walk($value,function ($v,$k) use (&$value,$field){
                    if (!in_array($k,$field)) unset($value[$k]);
                });
                $buffer[$id]=$value;
            }
            return $buffer;
        }

        //id_arr
        foreach ($data as $value) {
            $buffer[]=$value[$key];
        }
        return $buffer;
    }



//用法demo:
//原记录集:
$data=array(
array('id'=>1,'name'=>'dubox','age'=>25,'girlfriend'=>'苏打绿'),
array('id'=>4,'name'=>'小春子','age'=>21,'girlfriend'=>'不知道'),
array('id'=>9,'name'=>'白痴','age'=>71,'girlfriend'=>'寡妇'),
);

$ids=array_column($data,'id');
//out: array(1,4,9);

$info=array_column($data,'name','girlfriend');
//out: array('dubox'=>'苏打绿','小春子'=>'不知道','白痴'=>'寡妇');

$cache=array_column($data,'id','name,age,girlfriend');
//out: array(
1=>array('name'=>'dubox','age'=>25,'girlfriend'=>'苏打绿'),
4=>array('name'=>'小春子','age'=>21,'girlfriend'=>'不知道'),
9=>array('name'=>'白痴','age'=>71,'girlfriend'=>'寡妇'),
);