开发者

Can an array refer to itself

I have this associative array, where key2 and key5 are always going to have the same value as key1. Is it possible to set their values by referring to the array itself or any other suggestions to remove the value duplication?

$arr = array(
 开发者_StackOverflow中文版  'key1' => 'some value',
   'key2' => 'some value', //same as key1 and will always stay as key1
   'key3' => 'some other value',
   'key4' => 'yet another',
   'key5' => 'some value'  //same as key1 and will always stay as key1
);


You could apply a & reference after the array has been declared:

$arr = array(...);
$arr["key2"] = & $arr["key1"];
$arr["key5"] = & $arr["key1"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜