Jump to content

Recommended Posts

I'm sure this is a pretty basic question, but I used search and could not find anything. Probably because I don't know exactly what I'm looking for. Here's my problem. I'm creating an array and want the key to have the same name as the variable I'm using for that keys value.

 

$variable = 'value';

$somearray = array( ' ? ' => $variable );

 

Basically where the question mark is I want it to pull the word ' variable ' from the variable $variable and use it as the key. The purpose of this is I'm passing unknown (unknown inside the function that is) params to a function that loops through these params and enters them into an array which is returned from the function. Subsequent code will know what is needs from $somearray.

Link to comment
https://forums.phpfreaks.com/topic/40592-solved-copy-variables-name/
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.