Last active
September 21, 2019 01:38
-
-
Save gonssal/bc49d34af5ae134dace16e3a44311be7 to your computer and use it in GitHub Desktop.
Using PHP's ArrayRecursiveIterator to find a key and its value in any multidimensional array.
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 | |
$iterator = new RecursiveIteratorIterator( | |
new RecursiveArrayIterator($multidimensional_array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY), | |
RecursiveIteratorIterator::SELF_FIRST | |
); | |
foreach ($iterator as $key => $value) { | |
if ($key === $search) { | |
$your_data = $value; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment