note 42156 deleted from language.types.array by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 03 Jul 2004 13:15:16 +0000 |
| Subject: | note 42156 deleted from language.types.array by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72416@lists.php.net to get a copy of this message | ||
Note Submitter: joeldegan@yahoo.com
----
With arrays sometimes you need variable depth arrays.
For instance:
create just in PHP an array from
<? $arr = array("a","b","c"); ?>
That looks like
<? Array([a] => Array([b] => Array([c] => Array()))) ?>
I tried various ways like ${$parts}='test'; etc in the below and finally found that you
can just create a string and eval it.
It can be done like the following:
<?
$parts = "$"."test";
while(list($key,$val)=each($arr)){
$parts .= "['$val']";
}
$parts .= "='test';";
eval($parts);
print_r($parts);
?>
Comes in handy (and saves a LOT of coding) when doing things with xml and rdf where you do not know
the actual depth the array will need to be.