Fwd: Re: [PHP] Remove value from array
| From: | bvr@xs4all.nl | Date: | Thu, 17 Jan 2002 02:16:48 +0000 |
| Subject: | Fwd: Re: [PHP] Remove value from array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-80865@lists.php.net to get a copy of this message | ||
I also just discovered how to check for these keys with no value as isset() will return false:
<?php
$arr = array("foo" => "bar");
$arr["foo"] = NULL;
print_r($arr); // you can see "foo" is still there
if (array_key_exists("foo", $arr))
{
echo("it's there!");
}
?>
bvr.
==================BEGIN FORWARDED MESSAGE==================
Yes, I read that one on this list and it reminded me
of a problem where i used $Arr['cyanide'] = NULL;
because the key was still defined after this.
never figured unset() would do the trick because I
always did = NULL.
bvr.
On Wed, 16 Jan 2002 17:45:21 -0500, Erik Price wrote:
>This is a good one I just learned last week -- unset the variable. That
>is,
>
>unset($Arr[2]);
>
>or
>
>unset($Arr['cyanide']);
>
>from what I understand, the discovery of this easy way to do this was
>accidental. See the second annotation of "array_splice()" in the PHP
>manual here for the details:
>http://www.php.net/manual/en/function.array-splice.php
===================END FORWARDED MESSAGE===================