4

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

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.

3 Answers 3

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

or use references

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


$val = 'bye'; // both are updated
Sign up to request clarification or add additional context in comments.

4 Comments

The only issue is the array is defined in a class. the above won't work. Sorry. Didn't realize that would be an issue.
it'll work fine. obviously copy paste wont work. references can be confusing.
i'll mark this as the answer. i think i have a syntax error which is cause issues. thanks.
quick follow up as to why the code wasn't working. my error was because i was trying to do actual "code" outside of a function in a class. thanks again.
0

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'];

Comments

0

If you want to have possibility to modify them using either of keys, you are looking for references.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.