Multiple keys with identical values ​​in an array

Basically what I want to do is have 2+ different keys pointing to the same value.

Sort of:

"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 indicate values.

+4
source share
3 answers
 $val = 'hi'; $arr = array( 'a1' => $val, 'a2' => $val ); 

or use links

 $val = 'hi'; $arr = array( 'a1' => &$val, 'a2' => &$val ); $val = 'bye'; // both are updated 
+4
source

Why not configure the parent array, configure 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']; 
0
source

If you want to be able to modify them using any of the keys, you are looking for references .

0
source

Source: https://habr.com/ru/post/1386762/


All Articles