note 64442 added to function.isset
| From: | soywiz@php.net | Date: | Fri, 14 Apr 2006 13:12:06 +0000 |
| Subject: | note 64442 added to function.isset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108063@lists.php.net to get a copy of this message | ||
Sometimes you have to check if an array has some keys. To achieve it you can use "isset"
like this: isset($array['key1'], $array['key2'], $array['key3'],
$array['key4'])
You have to write $array all times and it is reiterative if you use same array each time.
With this simple function you can check if an array has some keys:
<?php
function isset_array() {
if (func_num_args() < 2) return true;
$args = func_get_args();
$array = array_shift($args);
if (!is_array($array)) return false;
foreach ($args as $n) if (!isset($array[$n])) return false;
return true;
}
?>
Use: isset_array($array, 'key1', 'key2', 'key3', 'key4')
First parameter has the array; following parameters has the keys you want to check.
----
Server IP: 130.206.1.5
Probable Submitter: 81.202.114.192
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.isset.php
Edit -- http://master.php.net/note/edit/64442
Del: integrated -- http://master.php.net/note/delete/64442/integrated
Del: useless -- http://master.php.net/note/delete/64442/useless
Del: bad code -- http://master.php.net/note/delete/64442/bad+code
Del: spam -- http://master.php.net/note/delete/64442/spam
Del: non-english -- http://master.php.net/note/delete/64442/non-english
Del: in docs -- http://master.php.net/note/delete/64442/in+docs
Del: other reasons-- http://master.php.net/note/delete/64442
Reject -- http://master.php.net/note/reject/64442
Search -- http://master.php.net/manage/user-notes.php