且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP变量的变量——可变变量

更新时间:2022-04-09 22:02:06

可变变量的概念:通过获取一个变量的值做为另外一个变量的名称来操作变量,就是可以变量。

Java代码  PHP变量的变量——可变变量
  1. $method = "save".ucfirst($data_type['input_table'])."_".$file_info['file_type'] ;  
  2.   
  3. $this->$method( &$file_info );  
  4.   
  5. for($i=1;$i<5;$i++){  
  6. $name = "name_".$i;  
  7. $$name='test'.$i;  
  8. }  
  9. $result=$this->_statement->{$method}($mode);  
  10. eval('$this->'.$_GET['flashreport'].'();');  
 
Java代码  PHP变量的变量——可变变量
  1. <?php     
  2. $a  = 'hello' ;   //普通变量      
  3. $$a  = 'world' ;  //可变变量 ,相当于 $hello='world';      
  4. echo  "$a $hello" ;  //输出:hello world     
  5. echo  $$a ;   //输出:world       
  6. echo  "$a ${$a}" ;  //输出:hello world     
  7. echo  "$a {$$a}" ;  //输出:hello world     
  8. $string = "beautiful";  
  9. $time = "winter";  
  10. $str = 'This is a $string $time morning!';  
  11. echo $str. "<br />";  
  12.   
  13. eval("\$str = \"$str\";");  
  14. echo $str;  
  15. This is a $string $time morning!  
  16. This is a beautiful winter morning!   
  17. eval('$a=55;');