note 91198 added to function.array-key-exists

From: Date: Fri, 29 May 2009 15:42:59 +0000
Subject: note 91198 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-156150@lists.php.net to get a copy of this message
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; } ---- Server IP: 209.41.74.194 Probable Submitter: 65.198.133.72 ---- Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/91198 Del: integrated -- https://master.php.net/note/delete/91198/integrated Del: useless -- https://master.php.net/note/delete/91198/useless Del: bad code -- https://master.php.net/note/delete/91198/bad+code Del: spam -- https://master.php.net/note/delete/91198/spam Del: non-english -- https://master.php.net/note/delete/91198/non-english Del: in docs -- https://master.php.net/note/delete/91198/in+docs Del: other reasons-- https://master.php.net/note/delete/91198 Reject -- https://master.php.net/note/reject/91198 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156150) next »