我在编写以下语法php语法时遇到问题: -
简单数组语法:
$array = array(
"a" => 1,
"b" => 2,
"c" => 3
)
简单的foreach语法:
foreach ($countries as $key => $value){
echo $key; echo $value;
}
现在,我想结合以上2: -
$array = array{
foreach ($countries as $key => $value){
$key => $value,
}
}
我怎么写呢?或者我只能构造一个字符串看起来像数组括号内的单词?
答案 0 :(得分:6)
你应该写
foreach ($countries as $key => $value){
$array[$key] = $value;
}
答案 1 :(得分:0)
请尝试以下代码
$array =$array+$country;
print_r($array);