Skip to content

Instantly share code, notes, and snippets.

@TorbenKoehn
Created June 26, 2013 09:40
Show Gist options
  • Select an option

  • Save TorbenKoehn/5866154 to your computer and use it in GitHub Desktop.

Select an option

Save TorbenKoehn/5866154 to your computer and use it in GitHub Desktop.
Polyfill for the PHP 5.4 array_column() function (untested)
<?php
//Signature: array array_column ( array $input , mixed $column_key [, mixed $index_key ] )
if( !function_exists( 'array_column' ) ):
function array_column( array $input, $column_key, $index_key = null ) {
$result = array();
foreach( $input as $k => $v )
$result[ $index_key ? $v[ $index_key ] : $k ] = $v[ $column_key ];
return $result;
}
endif;
@TorbenKoehn
Copy link
Copy Markdown
Author

@fedir: It's some kind of templating style if you put it as that, I just want to keep curly brackets out of the global scope just as in templates.
It has no deeper meaning, it was more an emotional thing, do it as you like of course

Also, sorry for the late answer hehe :)

@AlexSkrypnyk
Copy link
Copy Markdown

Use https://github.com/ramsey/array_column for proper replacement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment