How to create a PHP associate array from an array of keys?
I have a csv file with a field that explodes into an array of representing
a category tree. So: food>fruit>red>apple explodes into
array('food', 'fruit', 'red', 'apple')
It is supposed to be a tree, though. So what I need to do is either
explode the string into a nested array, or create one from the array
resulting from the explode.
array('food' => array('fruit' => array('red' => array('apple'))))
I'm thinking since there is unfortunately no aexplode (associative), that
it will need to be a function called iteratively, but I'm unsure as to
keeping a static value on each call that is an array key... I don't know
that one can do:
$a = "b['food']";
${$a} = ...
No comments:
Post a Comment