note 103342 modified in language.types.array by danbrown

From: Date: Fri, 08 Apr 2011 15:16:56 +0000
Subject: note 103342 modified in language.types.array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178635@lists.php.net to get a copy of this message
I was in need to get value of key which resides at any level in an multidimensional array. Unfortunately there is no such array function. So I write my own as below... <?php function array_get_key_val($key, $heystack) { if (is_array($heystack)) { foreach ($heystack as $k => $v) { if ($k == $key) { return $v; } elseif (is_array($v)) { return array_get_key_val($key, $v); } } } return FALSE; } ?> Hope this will help to few. --was-- I was in need to get value of key which resides at any level in an multidimensional array. Unfortunately there is no such array function. So I write my own as below... function array_get_key_val($key, $heystack) { if (is_array($heystack)) { foreach ($heystack as $k => $v) { if ($k == $key) { return $v; } elseif (is_array($v)) { return array_get_key_val($key, $v); } } } return FALSE; } Hope this will help to few. http://php.net/manual/en/language.types.array.php

« previous php.notes (#178635) next »