Skip to content

Instantly share code, notes, and snippets.

@TorbenKoehn
Created June 26, 2013 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TorbenKoehn/5866154 to your computer and use it in GitHub Desktop.
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;
@fedir
Copy link

fedir commented Jul 11, 2013

Why not to use same brackets syntax , for if and for.

@TorbenKoehn
Copy link
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

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