You are here: Re: how to replace an array key and keep the position? « PHP Language « IT news, forums, messages
Re: how to replace an array key and keep the position?

Posted by ZeldorBlat on 10/05/07 19:16

On Oct 4, 6:22 pm, Ian Hobson <ian.hob...@ntlworld.com> wrote:
> IIRC the order of the keys is NOT defined, except that integer keys
> appear in increasing order. If this is right, your approach relies on
> implementation details that may change. With that warning....
>

The elements of the array do have an order -- and it isn't necessarily
the order of the keys, even when using integers. It's the order in
which they were added to the array. If they had no order then
functions like sort() would be pretty useless. Try this:

$a = array();

$a[1] = 'foo';
$a[0] = 'bar';
$a[2] = 'baz';

print_r($a);

You'll get the same result if you replace the print_r() with a
foreach.

 

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

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