Friday, June 19, 2009

Variable Variables

Have you really thought about how dynamic PHP can be? Well seriously if you haven't, check this out! Variable variables.

<?php

$a = 'hello';
$hello = 'hello world!';
echo $$a;

// outputs as "hello world!"

?>

Why? $$a is evaluated automatically by PHP into $hello, since $a is 'hello'.

No comments: