开发者

Is it possible to append to a nested array from within an outer layer of that array?

<?php

$x = array
(
    'test' => array('asd', 'works'),
    'blah' => $x['test'] + array('more')
);

print_r($x);
?>

Basically, is it possible for 'b开发者_如何学Clah' to have the contents of 'test'?


This is not possible in the circular way you have. However, you could do the following to achieve the desired result.

$x = array
(
    'test' => array('asd', 'works')
);

$x['blah'] = $x['test'];
array_push($x['blah'], 'more');

print_r($x);


you cannot do it while declaring the array.

however, you can assign the same values with a different key.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜