You are here: Re: array key reassignment methodology « All PHP « IT news, forums, messages
Re: array key reassignment methodology

Posted by PhilM on 08/12/05 05:38

"PhilM" <philm@nospam.com.am> wrote in message
news:42fbfceb$0$8999$afc38c87@news.optusnet.com.au...
> I would like some assistance in methodology to reassign/reset array keys
to
> consecutive numbering, while keeping in sync a second array that uses the
> key of the first as it's key set.
> *** note php4 only available ***
> $links is used to generate main page links.
> $gallery is used to generate links on the $links page that has the same
key
> value.
>
> The output below was produced using my config generator form, which
enables
> adding/deletion of links and associated galleries, which accounts for the
> gaps in the $links key.
>
> ///// LINK LIST (TOP OF PAGE LINKS) /////
> $links[0]=array('home'=>'Home');
> $links[1]=array('service'=>'Services');
> $links[3]=array('people'=>'Portraits');
> $links[5]=array('fundraise'=>'Fundraise');
> $links[6]=array('events'=>'Events');
> $links[7]=array('contact'=>'Contact');
> ///// GALLERY LIST /////
> $gallery[0]=array('service'=>'Service','reception'=>'Reception');
>
$gallery[3]=array('family'=>'Family','children'=>'Children','adults'=>'Adult
> s');
> $gallery[5]=array('cards'=>'Cards','leaflets'=>'Leaflets');
>
ok, this is what I eventually came up with... is there a smoother way?

$indexer=0;
foreach (array_keys($links) as $linkKey){
$collecter[$indexer]=$linkKey;
$indexer++;
}
foreach (array_keys($collecter) as $linkKey){
if ($links[$collecter[$linkKey]]){
$linksHolder[$linkKey]=$links[$collecter[$linkKey]];}
if ($gallery[$collecter[$linkKey]]){
$galleryHolder[$linkKey]=$gallery[$collecter[$linkKey]];}
}
$links=$linksHolder;$gallery=$galleryHolder;

 

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

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