Header menu

_________________________________________________________________________________

Monday, 16 December 2013

Create variable at runtime in php

Hey ... Today we are going to create variable at runtime from an array;
I have declared an array named $arr and i am iteration array using foreach loop
and for each element creating a variable using   $$ar .
And at last i am printing the created variables.

<?php
$arr=array("1"=>"abc","2"=>"def");
echo "<pre>";
print_r($arr);
foreach($arr as $ar){
   
    $$ar="success:".$ar;
}
echo $abc;
echo "<br/>";
echo $def;

?>


Run the above example , to understand more ...