php foreach as variable
Posted
by user167850
on Stack Overflow
See other posts from Stack Overflow
or by user167850
Published on 2010-05-27T16:14:31Z
Indexed on
2010/05/27
16:21 UTC
Read the original article
Hit count: 223
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
© Stack Overflow or respective owner