Jump to content

Create Array Keys On The Fly


silkfire

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/268663-create-array-keys-on-the-fly/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.