Home Tutorial Php Phpbasics Tutorial PHP Variable variables

 
 

PHP Variable variables
Posted on: March 17, 2010 at 12:00 AM
This PHP tutorial describes about variable variables in PHP. Learn how to declare & how to use in class user variable variable in PHP etc.

PHP Variables variable:

Variables variable is a new kind of technique of using variables, in this technique we need to use more than one variable and we can use those variables dynamically.

As in the following examples we can see the use of variable variable both in general use as well as in OOP concept.

PHP Variables Variable Example:

<?php

$a="Rose";

$$a="India";

echo "$a ${$a}";

?>

Output:

Rose India

 

Example:

<?php

class foo

{

var $is="This is inside the class";

}

$is="variable";

$o=new foo;

$m="my variable";

echo $o->is."<br/>";

$bas=array('this','is','outside');

echo $o->$bas[1]."<br/>";

$o->m;

?>

 

Output:

This is inside the class
This is inside the class

Related Tags for PHP Variable variables:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.