Skip to content

Instantly share code, notes, and snippets.

@Bizunow
Last active October 25, 2017 09:31
Show Gist options
  • Save Bizunow/84a3cf7138d5b43af988a8580a123a9a to your computer and use it in GitHub Desktop.
Save Bizunow/84a3cf7138d5b43af988a8580a123a9a to your computer and use it in GitHub Desktop.
[PHP array_deep_column] array column for array of objects #php
// array_deep_column($wallData->items, 'likes.count');
function array_deep_column($array, $path)
{
$currentArray = $array;
$path = explode('.', $path);
foreach ($path as $sub) {
if (is_object($currentArray)) {
$currentArray = get_object_vars($currentArray);
}
$currentArray = array_column($currentArray, $sub);
}
return $currentArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment