note 65714 modified in function.array-walk by thiago

From: Date: Tue, 22 Jul 2008 16:58:24 +0000
Subject: note 65714 modified in function.array-walk by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142508@lists.php.net to get a copy of this message
no sure if this should go under array-walk but it does what i need, it searches a multidimensionial array by using an array to walk it, it either returns a value or an array. <?php function walker($walk, $array) { if (count($walk) >0) { foreach($array as $key => $value) { if ($key == $walk[0]) { if (is_array($value)) { unset($walk[0]); return walker(array_values($walk), $value); } else { if (isset($value)) { if (count($walk) == 1) { return $value; } else { return 0; } } else { return 0; } } } } return 0; } else { return $array; } } ?> --was-- no sure if this should go under array-walk but it does what i need, it searches a multidimensionial array by using an array to walk it, it either returns a value or an array. function walker($walk, $array) { if (count($walk) >0) { foreach($array as $key => $value) { if ($key == $walk[0]) { if (is_array($value)) { unset($walk[0]); return walker(array_values($walk), $value); } else { if (isset($value)) { if (count($walk) == 1) { return $value; } else { return 0; } } else { return 0; } } } } return 0; } else { return $array; } } http://php.net/manual/en/function.array-walk.php

« previous php.notes (#142508) next »