|
Posted by Kimmo Laine on 11/15/36 11:23
"meltedown" <groups2@reenie.org> kirjoitti
viestissδ:wlpJe.1011472$3V6.256377@fe04.news.easynews.com...
> According to the manual, key() returns the index element of the current
> array position.
>
> I have an array
> Array
> (
> [7857] => Soaps
> [7861] => Sponges
> [7863] => Bath Brushes
> [7858] => Toothpastes
> [7865] => Colognes
> [7960] => Miscellaneous
> )
>
>
> When I go
> $pline=key($plines);
> I get nothing for $pline.
>
> What is going on ?
> Is it possible that the array does not have a current array position ?
where ever the internal pointer of the array points, there's a function
called reset that - suprisingly resets the array pointer to the primary
element of the array.
Try the following example:
<?php
$fruits = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple',
);
reset($fruits);
$key = key($fruits);
$value = current($fruits);
echo "$key = $value";
?>
That should be sort of what you wanted.
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <eternal.erectionN0@5P4Mgmail.com>
[Back to original message]
|