Jump to content

Recommended Posts

I have this indirect Reference i wonder what's the usage of this

 

$name = "Air nike";

$$name = "Registered item";

print $AirNike;

 

 

I was thinking to put save all the items that are registered in a document by date and I was thinking of this technique and wanted to make sure it was ok. What would be a good place to implement a technique as the indirect Reference anyways?

Link to comment
https://forums.phpfreaks.com/topic/194342-proper-use-of-indirect-reference/
Share on other sites

Not entirely sure this is ideal. I never use indirect references.

 

It would be far better to use an array:

 

$names['AirNike'] = 'Registered item';

$names['Adidas'] = 'Registered item';

print $names['AirNike'];

 

That is far more manageable and flexible. PHP has lots of array functions :)

what you are referring to as "Indirect References" are commonly/correctly called Variable Variables

 

so your script would look like this

$name = "Air nike";
${$name} = "Registered item";
print $AirNike;

 

The only problem is that you can't spaces in a variable name.. So $name would have to be "AirNike" insted of "Air Nike"

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.