arrayOne + foreach loop = arrayTwo<?php /* version +7 */$input = array("teamA","teamB","teamC");foreach($input as &$value){ $assign = "50"; /* The data just temp */ $data = array($value=>$assign);}echo $data["teamA"];?>
2 回答
繁星coding
TA贡献1797条经验 获得超4个赞
我想你正在寻找这个:
$input = array("teamA","teamB","teamC");
$data = [];
foreach($input as $value){
$assign = "50"; /* The data just temp */
$data[$value] = $assign;
}
echo $data["teamA"];
如果对于所有键都相同:$assign
$data = array_fill_keys($input, 50);
温温酱
TA贡献1752条经验 获得超4个赞
<?php
$input = array("teamA","teamB","teamC");
$data = array();
foreach($input as $value){
$assign = "50";
$data[$value] = $assign;
}
echo $data["teamA"];
?>
将新的键值对分配给数组,可以通过以下方式访问:,其中键由初始给定数组的值组成$data[$value] = $assign;$input = array("teamA","teamB","teamC")
- 2 回答
- 0 关注
- 87 浏览
添加回答
举报
0/150
提交
取消