I need to define a set of variables to a series
$charta ='<img src="'.$_SERVER["DOCUMENT_ROOT"].'/output/pdf/charts/aplha.png" alt ="" />';
$chartb ='<img src="'.$_SERVER["DOCUMENT_ROOT"].'/output/pdf/charts/bravo.png" alt ="" />';
$chartc ='<img src="'.$_SERVER["DOCUMENT_ROOT"].'/output/pdf/charts/charlie.png" alt ="" />';
etc ...
Rather than define them all like this I want to use a loop to define them using an array
$names = array (
'aplha' => 'a',
'bravo' => 'b',
'charlie' => 'c'
);
So I tried this, after reading about variable variables in the PHP documentation
foreach($names as $k=>$v){
${'chart' . $v} ='<img src="'.$_SERVER["DOCUMENT_ROOT"].'/output/pdf/charts/'.$k.'.png" alt ="" />';
}
And this works.
My simple question is - is this good / acceptable practice? I explained my method to a more experienced programmer and they told me to find another way that didn't include variable variables, because they are bad practice - but I can't think of what's wrong with this, nor how to do it better.
Thoughts?