You are here: Re: Replacing key in associative array « PHP Language « IT news, forums, messages
Re: Replacing key in associative array

Posted by Geoff Berrow on 01/30/07 10:57

Message-ID: <BkFvh.196175$MO2.66573@fe3.news.blueyonder.co.uk> from
David Smithz contained the following:

>>Geoff said:
>> $array['key number 2']=$array['key2'];
>> //optionally
>> unset($array['key2']);
>
>Thanks for this Geoff. Works. However does lose the ordering of my array. Is
>there a way of maintaining the order as I guess the above puts in a new
>element, and then just removes the old one.
>
>How can I as well maintain the order.

It's difficult to advise without knowing exactly what you want to do but
you could make a copy of the array changing the keys as necessary.

foreach($array as $key=>$value){
if($key=="key2"){
$key="key number 2";
}
$temparray[$key]=$value;
}
$array=$temparray;



--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011

 

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

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