开发者

Push array while defining the key

开发者 https://www.devze.com 2023-03-16 03:36 出处:网络
I have an array that looks like this: $daysArray = array(2=>array(\'#linkhere\',\'linked-day\')); I need to push another array into here but define the key.

I have an array that looks like this:

$daysArray = array(2=>array('#linkhere','linked-day'));

I need to push another array into here but define the key.

I have tried:

$value= $key.'=>array("#$event","linked-day")';
//$value= 2=>array('/weblog/archive/2004/Jan/02','linked-day')
array_push($daysArray, 开发者_如何学JAVA$value);


If you want to append another array onto your primary array you can use:

$daysArray[$key] = array($event, "linked-day");

Doc: http://us.php.net/array_push

From the Docs:

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. 


you to try:

$result = array_merge($array1, $array2);

0

精彩评论

暂无评论...
验证码 换一张
取 消