如何从变量字符串创建数组变量


How to create array variable from variable string

在这种情况下如何从文本创建变量:

$option["b"] = 'text';
$a['field'] = 'option["b"]';

这样做不起作用:

$x=${$a〔'字段'〕};

在这种情况下,结果为null,但变量$x值应为'text'

我认为通过文本实现这一点的唯一方法是不使用键。您可以通过字符串分配数组变量,但不能通过密钥本身分配:

$option['b'] = 'text';
$var = "option";
$next = $$var; //variable variable which reads string as variable name
$a['field'] = $next['b'];

如果你给我一个例子来表达这个目的,我可能会想出一个函数来满足你的需求。