silkfire Posted September 22, 2012 Share Posted September 22, 2012 I tested a feature today I thought would be possible but seems it is not. I want to create an array and one of the values references a preciously created value. I like elegant code that's why I'm asking. $a = array( 'test' => 'cat1', 'nest' => 'cat66', 'gest' => $a['mest'] ); var_dump($a); One could think this will give you "Notice: undefined index mest", but it will actually say "Undefined variable $a". Any solution to this? Quote Link to comment https://forums.phpfreaks.com/topic/268663-create-array-keys-on-the-fly/ Share on other sites More sharing options...
Barand Posted September 22, 2012 Share Posted September 22, 2012 <?php $a = array( 'test' => 'cat1', 'nest' => 'cat66' ); $a['gest'] = $a['nest']; var_dump($a); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268663-create-array-keys-on-the-fly/#findComment-1380017 Share on other sites More sharing options...
Christian F. Posted September 22, 2012 Share Posted September 22, 2012 You want to create a hammer, using the hammer you're creating. There's a "slight" logical problem there. Also, why would you want to do this? I don't think you're going about it, whatever it is that you're trying to do, in the right manner. If you explain what your starting point and end goal is, we might be able to suggest a better course of action. Quote Link to comment https://forums.phpfreaks.com/topic/268663-create-array-keys-on-the-fly/#findComment-1380022 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.