在PHP中将字符串转换为变量?

Rap*_*eta 1 php variables

如何在PHP中将字符串设置为文字变量?基本上我有一个类似的数组

$data['setting'] = "thevalue";
Run Code Online (Sandbox Code Playgroud)

我想将其转换'setting'$setting使$setting成为"thevalue".

谢谢你的帮助!

Art*_*ius 7

请参阅PHP变量变量.

你的问题不是很清楚,但也许你想要这样的东西:

//Takes an associative array and creates variables named after
//its keys
foreach ($data as $key => $value) {
    $$key = $value;
}
Run Code Online (Sandbox Code Playgroud)


Ign*_*ams 5

extract() 将获取数组的键并将它们转换为具有数组中相应值的变量.