Php 从具有动态名称和动态变量的数组中获取信息

Php 从具有动态名称和动态变量的数组中获取信息,php,arrays,Php,Arrays,如何从具有动态名称和动态变量的数组中获取信息? 现在我试图从名为的数组中获取信息,该数组存储在名为$command[0]的var中。我的代码不起作用 $replacement_iterations = substr_count($pre_body, '*|'); var_dump($replacement_iterations); $iteration_count = 0; while($replacement_iterations > $iteration_count) { $co

如何从具有动态名称和动态变量的数组中获取信息? 现在我试图从名为的数组中获取信息,该数组存储在名为
$command[0]
的var中。我的代码不起作用

$replacement_iterations = substr_count($pre_body, '*|');
var_dump($replacement_iterations);
$iteration_count = 0;
while($replacement_iterations > $iteration_count) {
   $command = explode(':', get_string_between($pre_body, "*|", "|*"));
   $replace_body = '*|' .  get_string_between($pre_body, "*|", "|*") . '|*';
   $put_body = $command[0].'[' . $command[1] . ']';
   var_dump($put_body);
   $pre_body = str_replace($replace_body, $command, $pre_body);
   var_dump($pre_body);
$iteration_count++;
}

只需使用变量:

$myArray = ['a' => 'a', 'someVar' => 'samavar'];

$command = [
    'myArray',
    'someVar'
];

var_dump(
    ${$command[0]}[$command[1]]
);
// -> string(7) "samavar"