-
-
Save fedir/5975369 to your computer and use it in GitHub Desktop.
Prosthesis for PHP < 5.5 to implement array_column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!function_exists('array_column')) { | |
function array_column(array $input,$column_key,$index_key=null) { | |
$r=array(); | |
foreach($input as $k=>$v) | |
$r[$index_key?$v[$index_key]:$k]=$v[$column_key]; | |
return $r; | |
} | |
}; |
Quite interesting solution, thanks. I know what my solution is as simple as it possible, it's clean and it works for me.
His solution is more complex, and I've no extra time to analyze all his code to choose this extended solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the solution from author of this function would be better
https://github.com/ramsey/array_column/blob/master/src/array_column.php