PHP: Simple Dynamic Variable Example


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. /*
  4. How to dynamically cast a variable
  5. */
  6.  
  7. $a = 'kevin';
  8. $b = 'mary';
  9. $c = 'joe';
  10. $d = 'larry';
  11. $e = 'audrey';
  12.  
  13. $students = array('a', 'b', 'c');
  14.  
  15. foreach( $students as $seat ){
  16. echo $$seat . "<br />";
  17. }
  18.  
  19.  
  20. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.