如何从字符串变量中获取值?
$Member_Student = 3600;
$selectedItem = "Member_Student";
$price = "$" . $selectedItem;
print_r($price); //prints $Member_Student instead of 3600
我不能使用 eval 函数。
最佳答案
使用curly braces to denote a variable :
$Member_Student = 3600;
$selectedItem = "Member_Student";
$price = ${$selectedItem};
print_r($price); // prints 3600
关于来自字符串的 PHP 变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16339658/