我有一个数组
$variables_a = array(
'a' => $a,
'b' => $b,
'c' => $c
);
然后是另一个$variables_b = array('x','y','z')
,我想像这样循环遍历 B 数组:
foreach($variables_b as $var) {
$variables_c[] = array($var => $$var);
}
然后将 A & C 与$variables_combined = array_merge($variables_A, $variables_C)
我希望得到的输出是当print_r
我
Array
(
[a] => a
[b] => b
[c] => c
[x] => x
[y] => y
[z] => z
)
但我得到的是
Array
(
[a] => a
[b] => b
[c] => c
[0] => Array
(
[x] => x
)
[1] => Array
(
[y] => y
)
[2] => Array
(
[z] => z
)
)
如果我$feature_variables[] = array($feature => $$feature)
改为$feature_variables = array($feature => $$feature)
我得到
Array
(
[a] => a
[b] => b
[c] => c
[z] => z
)
即最后一个项目,$variables_b
但没有其他项目。那么我哪里错了?