Using Variable Variables to Create Associations
<?php
$favorite_color = 'blue';
$favorite_weapon = 'gun';
$favorite_drink = 'beer';
$favorite_things = array('color', 'weapon', 'drink');
foreach ($favorite_things as $thing) {
echo '<p>', $thing, ' = ', ${"favorite_{$thing}"}, '</p>';
}
?>
Related examples in the same category