0

Theres a multidimensional array, where are some keys like

$Array['nested']['product']['item']['name'] = 'It Works';

//I know the string saved in DB, thats like
$path = 'nested.product.item.name';


$split = explode('.',$path);

Is it possible to access the Array value based on the string path?

How to combine value from $split so I get nested $Keys

so

echo $Array[$Keys] will return 'It works';

ambiente
  • 31
  • 1

1 Answers1

0

Wrap each item of the $split array in square brackets, then join the array elements:

$Array['nested']['product']['item']['name'] = 'It Works';
$path = 'nested.product.item.name';
$split = explode('.',$path);
$exp = array_map(function($item) {
  return '"["' . $item . '"]"';
},$split);
$exp = join("", $exp);
Wais Kamal
  • 5,858
  • 2
  • 17
  • 36