Re: Getting key of value added to array with []?
| From: | 1LT John W. Holmes | Date: | Tue, 04 Feb 2003 12:26:15 +0000 |
| Subject: | Re: Getting key of value added to array with []? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134254@lists.php.net to get a copy of this message | ||
> Is there any way to get the key of an element added to an array with []?
> I need to use this for a reference to it. The only idea I can think of
> is to foreach through the array and use the last key looped through, but
> that seems very dirty.
If elements are only being added with [], then you should be able to keep a
count as you go.
Easy way would be to add it like this:
$array[$x++] = $your_value;
Then you'll have ($x-1) as the element just added, if you need it.
---John Holmes...