简体   繁体   English

数组中具有相同值的多个键

[英]Multiple keys with same values in an array

Basically what I'm looking to do is have 2+ different keys pointing to the same value. 基本上我要做的是有2个不同的键指向相同的值。

Something like: 就像是:

"AP7898",
"AP7841"    => array('loadStatusLoad' => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2',
                     'loadStatusStatus => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.3',                                      
               ),

both are ap7898 and ap7841 point to the values. 两者都是ap7898和ap7841指向的值。

$val = 'hi';
$arr = array(
  'a1' => $val,
  'a2' => $val
);

or use references 或使用参考

$val = 'hi';
$arr = array(
  'a1' => &$val,
  'a2' => &$val
);


$val = 'bye'; // both are updated

Why not setup the parent array, setup the first key/value pair, and copy to the second? 为什么不设置父数组,设置第一个键/值对,并复制到第二个?

$status = array( 'AP7898', 'AP7841' );

$status['AP7898'] = array('loadStatusLoad' => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.2',
                     'loadStatusStatus' => '.1.3.6.1.4.1.318.1.1.12.2.3.1.1.3');

$status['AP7841'] = $status['AP7898'];

如果您希望可以使用任一键修改它们,那么您正在寻找参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM