You are here: Re: single array to multidimensional « PHP Programming Language « IT news, forums, messages
Re: single array to multidimensional

Posted by Bob Stearns on 06/22/06 18:44

frizzle wrote:
> Hi there,
>
> I have a string, comma separated, with links and their respective URLs
> in it. Example:
> Google,http://www.google.com,Yahoo!,http://www.yahoo.com,WikiPedia,http://www.wikipedia.org
>
> etc, etc.
>
> i make an array of this with explode( ',', $string );
>
> now what i wonder is how can i turn this array into something like
> this:
>
> $array[0]['name'] = Google
> $array[0]['url'] = http://www.google.com
> $array[1]['name'] = Yahoo!
> $array[1]['url'] = http://www.yahoo.com
> $array[2]['name'] = WikiPedia
> $array[2]['url'] = http://www.wikipedia.org
>
> I hope/think this is all clear ...
>
> Frizzle.
>
Something like the following should do it:

$a = explode(",", $string)
for($i=0,$j=0; $i<count($a), $i+=2,$j++) {
$array[$j]["name"] = $a[$i];
$array[$j]["url"] = $a[$i+1];
}

 

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

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