sarathi Posted July 28, 2009 Share Posted July 28, 2009 Is it possible to have more than one key point to the same value in an array? Somtheing like this: $array = array('$key1, $key2' => '$value1'); Quote Link to comment Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 I guess you could pass the first by reference; <?php $array['key1'] = ' value1'; $array['key2'] =& $array['key1']; Quote Link to comment Share on other sites More sharing options...
zq29 Posted July 28, 2009 Share Posted July 28, 2009 I'm not sure if it is possible when creating the array, unless you manually define them to have the same value, but then affecting one won't affect the other. You could do it with a reference though: <?php $foo = array(1 => 'bar'); $foo[0] =& $foo[1]; echo "<pre>",print_r($foo),"</pre>"; ?> EDIT: Beaten to it. Quote Link to comment Share on other sites More sharing options...
sarathi Posted July 28, 2009 Author Share Posted July 28, 2009 Ok, I'll just set the second key to the first one, that will really shorten how much I have to write. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.