Jump to content

proper Use of Indirect Reference


co.ador

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"

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.