Skip to content

Instantly share code, notes, and snippets.

@fedir
Forked from TorbenKoehn/array_column.php
Last active December 19, 2015 15:18
Show Gist options
  • Save fedir/5975369 to your computer and use it in GitHub Desktop.
Save fedir/5975369 to your computer and use it in GitHub Desktop.
Prosthesis for PHP < 5.5 to implement array_column
<?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;
}
};
@fedir
Copy link
Author

fedir commented Oct 23, 2013

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