Reply to Re: Key()

Your name:

Reply:


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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация