开发者

Access array element within same array

开发者 https://www.devze.com 2023-01-27 03:11 出处:网络
Is this possible in PHP? $a = array(\'first\' => \'some value\', \'second\' => $a[\'first\']); Simply accessing an开发者_运维问答 array element within another element from the same array.Not

Is this possible in PHP?

$a = array('first' => 'some value', 'second' => $a['first']);

Simply accessing an开发者_运维问答 array element within another element from the same array.


Not with this syntax, because at the time $a['first'] is evaluated, $a is undefined. This would work though:

$a = array();
$a['first'] = 'some value';
$a['second'] = $a['first'];
0

精彩评论

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