|
Posted by "Richard Lynch" on 07/12/05 08:55
On Mon, July 11, 2005 10:56 am, Ben-Nes Yonatan said:
> Hi all!
>
> I got a string which include information for categories that I need to
> build, the string is built like this:
> $string = "val1~~val2~~val3~~val4~~val5"
>
> Now, I want to create from this string a multi dimensional array and not
> one dimension array as explode('~~', $string) will give me.
>
> The desired result from this string is:
>
> $array['val1'] = 'whatever';
> $array['val1']['val2'] = 'whatever';
> $array['val1']['val2']['val3'] = 'whatever';
> $array['val1']['val2']['val3']['val4'] = 'whatever';
> $array['val1']['val2']['val3']['val4']['val'5] = 'whatever';
That's not a valid array construct...
You can't have $array['val1'] be a string ('whatever') and also an array
(['val2'])..
Or is that 5 different examples?
Untested Code:
<?php
$string = "val1~~val2~~val3~~val4~~val5";
$keys = explode("~~", $string);
$keys = array_reverse($keys);
$array = 'whatever';
while (list(, $key) = each($keys)){
$array[$key] = $array;
}
var_dump($array);
?>
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|