faqts : Computers : Programming : Languages : PHP : kms : General : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 21 people (81%) answered Yes
Recently 6 of 8 people (75%) answered Yes


What does the $$ mean in variables?

Apr 29th, 2001 19:57
Philip Olson, Sheni R. Meledath, harry f, Nathan Wallace,

This is called "a variable variable", the manual entry is here :
  Variable variables                                         :
Essentially it works like this :  
  $a = 'bear';
  $b = 'a';
  print $$b;   // prints bear
Essentially $$b is like $a.  So :
  print $$b;   // prints bear
  print ${$b}; // prints bear
  print $a;    // prints bear
Take a little time with it, it's not as complicated as it may seem.  
For good measure, here are a couple tutorials on the subject :
A tip regarding variable variables and arrays, do it like so :
  $var = ${$array_name}[$key];