Indirect Variables
PHP Code Examples
[Download]   [Execute]
<?php 
$title = "Indirect Variable Names";
include '../head1.inc';

//
// The complex form ${$v} allows you to use a variable whose name is
// stored in another variable.
//
$al = 10;
$bill = 20;
$alice = 'howdy';

$mike = array('al', 'bill', 'alice');
foreach($mike as $fred)
	echo '$', $fred, " = ", ${$fred}, " ";
echo "<p>\n";

// 
// If you are appropriately perverse, you can generalize this to more levels.
//
$phil = 'fred';
$fred = 'alice';
echo ${${$phil}}, '<p>';
?>
</body>
</html>