Slicing a multi-dimensional PHP array across one of its elements

后端 未结 10 865
再見小時候
再見小時候 2020-12-28 15:51

Say for example you just queried a database and you recieved this 2D array.

$results = array(
    array(\'id\' => 1, \'name\' => \'red\'  , \'spin\' =&         


        
10条回答
  •  隐瞒了意图╮
    2020-12-28 16:37

    For those of you that cannot upgrade to PHP5.5 right now and need this function, here is an implementation of array_column.

    function array_column($array, $column){
        $a2 = array();
        array_map(function ($a1) use ($column, &$a2){
            array_push($a2, $a1[$column]);
        }, $array);
        return $a2;
    }
    

提交回复
热议问题