|
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]
|