我有以下数组:
$DS = array(
'name' => 'kim',
'star' => 'singh'
);
我想在其中添加新数组。这个数组:'relation' => '100','original' => '1'
最后,它看起来像:
$DS = array(
'name' => 'kim',
'star' => 'singh',
'relation' => '100',
'original' => '1'
);
我的尝试为:
$DS = array(
'name' => 'kim',
'star' => 'singh'
);
array_push($DS, array(
'relation' => '100',
'original' => '1'
));
echo '<pre>';
print_r($DS);
输出:
Array
(
[name] => kim
[star] => singh
[0] => Array
(
[relation] => 100
[original] => 1
)
)
演示:http://codepad.viper-7.com/ouzBxN
怎么办呢,请举个例子。
答案 0 :(得分:5)
$new_array = array_merge($DS, array(
'relation' => '100',
'original' => '1'
));
答案 1 :(得分:0)
这很好用:
$array1 = array(
'name' => 'kim',
'star' => 'singh'
);
$array2 = array(
'relation' => '100',
'original' => '1'
);
$array3 = $array1+$array2;
print_r($array3);