Skip to content

Instantly share code, notes, and snippets.

@bramus
Created December 6, 2016 19:42
Show Gist options
  • Save bramus/282353e43ef35e412bb765fa83463258 to your computer and use it in GitHub Desktop.
Save bramus/282353e43ef35e412bb765fa83463258 to your computer and use it in GitHub Desktop.
// key = value
array_reduce($input, function ($carry, $item) {
$carry[$item['x']] = $item['y'];
return $carry;
}, []);
// key = value, from array with keys
array_reduce(array_keys($input), function($carry, $key) use ($input) {
$carry[] = $input[$key]['x'];
return $carry;
}, []);
// extract column (if array_column were to be missing)
array_map(function($item) {
return $item['role'];
}, $input);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment