I would like to use foreach for a loop, although a list of arrays 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 using $ {$ arrayName} [] the best way to do this? Is there another option instead of using curly braces? It currently works, but I'm just wondering if there is a better alternative.
thank
source
share