2

How to handle if I want to create an array like in following example:

$value="test";
$array=[];
$path=[2,17,513];

Now, I want to build an array based on the available data which should look like:

$array['2']['17']['513']='test';

Anyone any idea?

I tried array_shift to prepare but I miss the point where the single array data will be transformed to an array key....

TheTom
  • 934
  • 2
  • 14
  • 40

1 Answers1

-1
$value="test";
$array=[];
$path = [2, 17, 513];

[$a, $b, $c] = explode(",", $path);


$array[$a][$b][$c] = $value;


print_r($array[$a][$b][$c]); //returns 'test'