Hello,
confusing title perhaps but what I am trying to do is this..
I have an array which contains arrays which contains arrays which contain arrays...and so forth.
These arrays are dynamically created so I don't always know whether the value of a key is a plain string or another array. example:
$main_array = array(
[key1] => "a string", // a simple
[key2] => array('hello','world'), //this key contains a simple array
[key3] => array(
[another_key] =>'foo',
[a_third_key] => array( 'foo', 'bar' )
)
);
So, $main_array is an array which contains three indexes, key1, key2 and key3 which contain values which could be another array etc.
Now, essentially what I'd like to be able to do is to replicate the code above as a string which can be echo'd to the browser. However I also need $main_array to be useable by the script and keys to be preserved if possible.
I've tried print_r() but that doesn't quite format things properly and had a bash at array_walk_recursive() to no real avail.
I'm a bit stuck, so if anyone has any ideas as to how to do this (or indeed a better method of storing similar data*) then please, share
Thanks in advance and I hope I've made sense.
Pablo.
*What I'm storing is a blog archive, the main keys are the years which contain an array of months which have posts and each month array contains all the relevant id's and titles of the blog.