|
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];
}
[Back to original message]
|