php - 将变量元素传递给具有元素名称的变量
问题描述
有没有办法将所有数组的元素传递给具有元素名称的变量?例如,如果我有以下数组:
$test['name']
$test['phone']
$test['address']
etc..
我想要一个快捷方式来输入这个:
$name = $test['name'];
$phone = $test['phone'];
$address = $test['address'];
etc..
解决方案
当然你可以使用$$
$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;
推荐阅读
- c++ - 如何在不使用 CMake 但仅使用 make 的项目中合并使用 CMake 的仅标头库?
- netlogo - NetLogo 中移动代理的滴答声和死亡问题
- r - 如何连接 2 个或更多数据框
- java - NullPointerException 引用 SharedPrefence java.lang.String, int
- javascript - 我如何在 Python Django 项目中使用 Jquery
- sqlite - 使用 SQLITE/Room 表列作为函数参数
- typescript - 方法读取正文时摩卡超时
- ios - 尝试从远程通知中快速从 didReceive 响应中运行函数
- python - 如何在 1 个 python 脚本中创建角色必需的命令和非角色必需的命令?
- python - 如何从字典列表创建数据框