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'); Link to comment https://forums.phpfreaks.com/topic/167814-two-keys-in-arrays/ 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']; Link to comment https://forums.phpfreaks.com/topic/167814-two-keys-in-arrays/#findComment-885050 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. Link to comment https://forums.phpfreaks.com/topic/167814-two-keys-in-arrays/#findComment-885052 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! Link to comment https://forums.phpfreaks.com/topic/167814-two-keys-in-arrays/#findComment-885054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.