Reply to Re: Key()

Your name:

Reply:


Posted by meltedown on 10/30/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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация