|
Posted by meltedown on 11/07/14 11:23
Kimmo Laine wrote:
> "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.
>
Thanks, that works.
Navigation:
[Reply to this message]
|