I hope the title is not too bad. I'm not an english person and this would even be hard to put in one sentece in my mothertounge...
My problem is follwing:
Iwant to build a multidimensional array from a string like so:
$string = "a-b-c";
$val = "something";
$array['a']['b']['c'] = $val;
I tried some ideas of mine and ended up with a fried brain... Hopefully you can help me! Thanks!
EDIT My approach:
function recursion($c, $p, $v) {
if (gettype($c) !== "array") $c = array();
$c[$p] = $v;
return $c;
}
foreach ($conf as $confLine) {
$params = preg_split('/-/', $confLine->getParam()); //Here comes "a-b-c"
$val = $confLine->getValue(); // The value
for ($i = 0; $i < count($params); $i++ ) {
$galleryConfig = recursion($galleryConfig, $params[$i], $val);
}
}
IMPORTANT I don't know how long the sting will be. If its a-b or a-b-c-d-e-f
explode()on - would be a start