Skip to content

Instantly share code, notes, and snippets.

@slav123
Created February 10, 2015 04:51
Show Gist options
  • Save slav123/85ec7d5c248cf5628e2e to your computer and use it in GitHub Desktop.
Save slav123/85ec7d5c248cf5628e2e to your computer and use it in GitHub Desktop.
return only given key from bigger array
<?php
/**
* capture only id from bigger array
*
* @param array $array input
* @param array $pkey primary key
*
* @return array
*/
function array_id($array, $pkey)
{
$checker = function($value) use ($pkey) {
if (array_key_exists($pkey, $value)) return $value[$pkey];
};
return array_map($checker, $array);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment