Last active
October 25, 2017 09:31
-
-
Save Bizunow/84a3cf7138d5b43af988a8580a123a9a to your computer and use it in GitHub Desktop.
[PHP array_deep_column] array column for array of objects #php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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