是否可以将所有数组元素传递给具有元素名称的变量? 例如,如果我有以下数组:
$test['name']
$test['phone']
$test['address']
etc..
我想输入一个快捷方式:
$name = $test['name'];
$phone = $test['phone'];
$address = $test['address'];
etc..
答案 0 :(得分:1)
确定您可以使用$$
$test['name'];
$test['phone'];
$test['address'];
$test['name'] = "John";
$test['phone'] = "987987987";
$test['address'] = "Asheville";
foreach($test as $key=>$val){
$$key = $test[$key];
}
echo $phone;