How to get the key of a specific index of array?
| From: | PhiSYS | Date: | Mon, 17 Nov 2003 19:51:19 +0000 |
| Subject: | How to get the key of a specific index of array? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-170090@lists.php.net to get a copy of this message | ||
How to get the key of a specific index of array?
It seems that key($_POST[$i]) is a wrong syntax.
I've worked around like this:
$allkeys = array_keys($_POST);
$allvalues = array_values($_POST);
for($I=3; $I < count($_POST); $I++) {
echo $allkeys[$I];
echo $allvalues[$I];
}
But I think that it will use the double of memory. And that won't be good
for long arrays.
So the cuestion is... Is there a PHP function to do this?
I successfully did it with ASP using Request.Form.Key(I) but I really do
prefer PHP when I'm free to choose the language.
Or how can I move the internal array pointer to a specified position to
be able to use the key() function?
As you probably noticed I started the $I counter at 3 because the first 3
values of the array will be used for other purposes. That's why I don't
want to use a foreach().
Thank you all!