php foreach as variable
- by user167850
I'd like to use foreach to loop though an array list and add an element to each array.
$tom = array('aa','bb','cc');
$sally = array('xx','yy','zz');
$myArrays = array('tom','sally');
foreach($myArrays as $arrayName) {
${$arrayName}[] = 'newElement';
}
Is the use of ${$arrayName}[] the best way to do this? Is there another option rather than using curly braces? It currently works but I'm just wondering if there is a better alternative.
Thanks