note 96866 added to function.array-search

From: Date: Fri, 19 Mar 2010 20:44:05 +0000
Subject: note 96866 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-167235@lists.php.net to get a copy of this message
I was looking around for a recursive search by keys in multidimensional arrays. After testing the ones in this thread seems noone accually works. So I put this one together, and it does what you expect it to do. You need to find the value for the key "han-solo". if( ($val = array_search_key('han-solo',$array)) !== false){ var_dump($val); } else { // No keys with the name "han-solo" } function array_search_key( $needle_key, $array ) { foreach($array AS $key=>$value){ if($key == $needle_key) return $value; if(is_array($value)){ if( ($result = array_search_key($needle_key,$value)) !== false) return $result; } } return false; } ---- Server IP: 85.19.212.230 Probable Submitter: 193.91.145.178 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/96866 Del: integrated -- https://master.php.net/note/delete/96866/integrated Del: useless -- https://master.php.net/note/delete/96866/useless Del: bad code -- https://master.php.net/note/delete/96866/bad+code Del: spam -- https://master.php.net/note/delete/96866/spam Del: non-english -- https://master.php.net/note/delete/96866/non-english Del: in docs -- https://master.php.net/note/delete/96866/in+docs Del: other reasons-- https://master.php.net/note/delete/96866 Reject -- https://master.php.net/note/reject/96866 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167235) next »