Search value by key in multidimensional array

/ Published in: PHP
Save to your folder(s)

Copy this code and paste it in your HTML
  1. function searchArrayValueByKey(array $array, $search) {
  2. foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $key => $value) {
  3. if ($search === $key)
  4. return $value;
  5. }
  6. return false;
  7. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.