Posted By

andreiabohner on 12/29/09


Tagged

php variable


Versions (?)

Variable variables samples


 / Published in: PHP
 

  1. // Sample 01:
  2. foreach($myData as $data){
  3. $v = 'myVar'.$data->getNb(); // output: $myVar1, $myVar2, ...
  4. $this->{$v} = $data->getVl();
  5. }
  6.  
  7. // Sample 02:
  8. $i = 10;
  9. $myVar10 = "foo";
  10. $foo = "bar";
  11. echo ${'myVar'.$i}; // output: foo
  12. echo ${$myVar10}; // output: bar

Report this snippet  

You need to login to post a comment.