You are here: Re: Key() « PHP Language « IT news, forums, messages
Re: Key()

Posted by meltedown on 11/15/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]


Удаленная работа для программистов  •  Как заработать на 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

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