如何从字符串变量中获取值?来自字符串的PHP变量值
$Member_Student = 3600;
$selectedItem = "Member_Student";
$price = "$" . $selectedItem;
print_r($price); //prints $Member_Student instead of 3600
我不能使用eval函数。
如何从字符串变量中获取值?来自字符串的PHP变量值
$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
使用2 $体征:
var_dump($$selectedItem)
要想从另一个变量的变量包含其名称使用print_r($$selectedItem);
change $selectedItem = "Member_Student";
to
$selectedItem = "$Member_Student";