note 81659 added to function.array-key-exists

From: Date: Sat, 08 Mar 2008 19:24:19 +0000
Subject: note 81659 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-136846@lists.php.net to get a copy of this message
Hi, i needed a recursive check is a key exists .. so here it is. I Hope it saves you time (-: <?php function array_key_exists_r($needle, $haystack) { $result = array_key_exists($needle, $haystack); if ($result) return $result; foreach ($haystack as $v) { if (is_array($v)) { $result = array_key_exists_r($needle, $v); } if ($result) return $result; } return $result; } $test = array( "L0" => array( "Über uns" => array( "name" => "Über uns", "MenuLast" => 0, "subMenu" => 8, "href" => "/admin/pages/admin_page_edit.php?nav_gid=1.1", "navid" => 1.1, "posid" => 1, "klickPath" => 0, ), "Was wir tun" => array( "name" => "Über uns", "MenuLast" => 0, "subMenu" => 8, "href" => "/admin/pages/admin_page_edit.php?nav_gid=1.1", "navid" => 1.1, "posid" => 1, "klickPath" => 0, ), ), ); dumpvar(array_key_exists_r('navid', $test), 'array_key_exists_r(\'navid\', $test)'); ?> Output: var array_key_exists_r('navid', $test)(boolean): 'true' ---- Server IP: 212.124.37.9 Probable Submitter: 88.67.52.151 ---- Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/81659 Del: integrated -- https://master.php.net/note/delete/81659/integrated Del: useless -- https://master.php.net/note/delete/81659/useless Del: bad code -- https://master.php.net/note/delete/81659/bad+code Del: spam -- https://master.php.net/note/delete/81659/spam Del: non-english -- https://master.php.net/note/delete/81659/non-english Del: in docs -- https://master.php.net/note/delete/81659/in+docs Del: other reasons-- https://master.php.net/note/delete/81659 Reject -- https://master.php.net/note/reject/81659 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136846) next »