Last active
January 28, 2022 23:35
-
-
Save agusputra/f1101b0bf74c6f4bbce8 to your computer and use it in GitHub Desktop.
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
| <?php | |
| function flattenArray($source, $key = null) | |
| { | |
| $result = array(); | |
| if ($key) { | |
| array_walk_recursive($source, function ($v, $k) use ($key, &$result) { | |
| if ($k === $key) { | |
| $result[] = $v; | |
| } | |
| }); | |
| } else { | |
| array_walk_recursive($source, function ($v, $k) use (&$result) { | |
| $result[] = $v; | |
| }); | |
| } | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment