You are here: Re: [PHP] creating of multi dimensional arrays with unknown depth « PHP « IT news, forums, messages
Re: [PHP] creating of multi dimensional arrays with unknown depth

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]


Удаленная работа для программистов  •  Как заработать на 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

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