Dynamic Variable in PHP

Introduction

In this article I explain variables of a variable or dynamic variables in PHP. A variable of a variable takes a value of a variable and threads which is the name of a variable. This is new feature of using variables and by using double dollar signs. This technique is called a dynamic variable in PHP. Those variables you can use a dynamically generated variable of variable as well as OOP Concept.  

Variable of variable in php.jpg

Example1

<?php

$b = 'hello';

$$b = 'Sharad Gupta';

echo $b.${$b};

?>

Output

variable1 in php.jpg

Example2

<?php

class name

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

var $m="my variable";

} 

$is="variable";

$o=new name;

$m='my variable';

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

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

echo $o->$bas[1];

$o->m;

 

?>

Output

variable in php.jpg


Similar Articles