co.ador Posted March 6, 2010 Share Posted March 6, 2010 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 More sharing options...
Anti-Moronic Posted March 6, 2010 Share Posted March 6, 2010 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 Link to comment https://forums.phpfreaks.com/topic/194342-proper-use-of-indirect-reference/#findComment-1022357 Share on other sites More sharing options...
Zane Posted March 6, 2010 Share Posted March 6, 2010 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" Link to comment https://forums.phpfreaks.com/topic/194342-proper-use-of-indirect-reference/#findComment-1022399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.