Skip to content

Instantly share code, notes, and snippets.

@atbradley
Created July 12, 2017 16:15
Show Gist options
  • Save atbradley/735d138fa22ed5997eb1207802f8b0e0 to your computer and use it in GitHub Desktop.
Save atbradley/735d138fa22ed5997eb1207802f8b0e0 to your computer and use it in GitHub Desktop.
<?php
/**
* Implement the array_column() function built-in to PHP 5.5+
*/
if (!function_exists('array_column')) {
function array_column($inpt, $columnKey, $indexKey = false)
{
if ( $indexKey !== false ) {
$outp = array_combine(
array_map(function($element) use($indexKey){return $element[$indexKey];}, $inpt),
array_map(function($element) use($columnKey){return $element[$columnKey];}, $inpt)
);
} else {
$outp = array_map(function($element) use($columnKey){return $element[$columnKey];}, $inpt);
}
return $outp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment