我有一个如下所示的数组:
$daysArray = array(2=>array('#linkhere','linked-day'));
我需要将另一个数组推入此处,但要定义密钥。
我试过了:
$value= $key.'=>array("#$event","linked-day")';
//$value= 2=>array('/weblog/archive/2004/Jan/02','linked-day')
array_push($daysArray, $value);
答案 0 :(得分:1)
如果要将另一个数组附加到主阵列上,可以使用:
$daysArray[$key] = array($event, "linked-day");
Doc:http://us.php.net/array_push
来自文档:
Note: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.
答案 1 :(得分:0)
你要尝试:
$ result = array_merge($ array1,$ array2);