Re: Comparing string to array
| From: | Robin Vickery | Date: | Tue, 19 Jun 2007 19:28:50 +0000 |
| Subject: | Re: Comparing string to array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257457@lists.php.net to get a copy of this message | ||
On 19/06/07, Richard Davey <rich@corephp.co.uk> wrote:
full_key_exists("test['sam'][]", $_POST) // returns true if key is set full_find_key("test['sam'][]", $_POST) // returns value of key or undef. function full_key_exists ($key, $array) { preg_match_all('/[^][]+/', $key, $branch); if (!sizeof($branch[0])) false; foreach ($branch[0] as $index) { if (!(is_array($array) && isset($array[$index]))) return false; $array = $array[$index]; } return true; } function full_find_key ($key, $array) { preg_match_all('/[^][]+/', $key, $branch); if (!sizeof($branch[0])) return; foreach ($branch[0] as $index) { if (!(is_array($array) && isset($array[$index]))) return; $array = $array[$index]; } return $array; }$userparam = "test['sam'][]";// How to check if $userparam exists in the $_POST array // and get all the values from it?