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

后端 未结 10 934
再見小時候
再見小時候 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:49

    I voted @Devon's response up because there really isn't a way to do what you're asking with a built-in function. The best you can do is write your own:

    function array_column($array, $column)
    {
        $ret = array();
        foreach ($array as $row) $ret[] = $row[$column];
        return $ret;
    }
    

提交回复
热议问题