creating of multi dimensional arrays with unknown depth
| From: | Ben-Nes Yonatan | Date: | Mon, 11 Jul 2005 17:56:50 +0000 |
| Subject: | creating of multi dimensional arrays with unknown depth | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-218467@lists.php.net to get a copy of this message | ||
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';
My problem is that the number of the dimensions is really unknown and can be changed from 1 to 20 as far as I know.
Is there a way to create such a dynamic depth in an automatic way and not by using lots of if's?
Thanks in advance,
Ben-Nes Yonatan
Canaan Surfing Ltd.