You are here: Re: Array questions « PHP Programming Language « IT news, forums, messages
Re: Array questions

Posted by Kim Andrι Akerψ on 08/20/07 11:08

Fabio wrote:

> Hi!
>
> Some question about array.
>
> - An array mantains always the order of item as inserted also if I
> use string keys? Or the items are "sorted" cause the hash of the key?
> I hope to be clear for this question :)

Yes, the order is maintained, unless you perform some sorting on it.

If you want to sort the array based on the keys (numerical and/or
string-based), you can use ksort() for that.
http://php.net/ksort

> - Can I know if a key is used?
> Something like in_array() but for the key, not for the value.

Sure, like this:

if (isset($array["key"])) {
// do something
}

http://php.net/isset

> - Can I remove an item from an array?

Yes, just pass the array key to the unset() function, like this:

unset($array["key"]);

http://php.net/unset

If you don't know the key, but have the value, use array_search() to
find the key.

http://php.net/array_search

> Thanks

No problem.

--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

 

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

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