Dynamic Variables

<?php

//Basic Example
for($i = 1; $i <= 4; $i++){
${a.$i} = 'value for $a' . $i;
}

echo '<strong>Basic Example</strong>' . '<br>';
echo $a1 . '<br>';
echo $a2 . '<br>';
echo $a3 . '<br>';
echo $a4 . '<br><br>';

//Advanced Example
$var_names = array('firstvar','secondvar','thirdvar','fourthvar');

foreach($var_names as $var_name){
${$var_name} = 'value for $' . $var_name;
}

echo '<strong>Advanced Example</strong>' . '<br>';
echo $firstvar . '<br>';
echo $secondvar . '<br>';
echo $thirdvar . '<br>';
echo $fourthvar . '<br>';

?>