note 91199 deleted from function.array-keys by danbrown

From: Date: Fri, 29 May 2009 17:19:52 +0000
Subject: note 91199 deleted from function.array-keys by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156156@lists.php.net to get a copy of this message
Note Submitter: timothy dot burgess dot 87 at gmail dot com ---- For multidimensional arrays, I noticed someone created a function called "extract_values_by_key" but it didn't work as I wanted it to... so I created a recursive function of my own that gets the values within a multidimensional array with a specific key and stores them into an array in case multiple keys match the search. /* Search for values by key within multidimensional array */ //Timothy Burgess //05.29.2009 function get_values_by_key($array, $needle_key) { static $result = array(); if (is_array($array)) { foreach ($array as $key => $value) { get_values_by_key($value, $needle_key); if ($key == $needle_key && $key != "0") { $result[] = $value; } } } return $result; }

« previous php.notes (#156156) next »