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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.