joined:June 15, 2006
I have a PHP code where is have to use a foreach statement multiple times (around 20 times). Is there a way using array and loop it so that i can make this code short.
In the example of the code below you will notice that the only part of the code that changes is the $id1,$id2,$id3......$id20 and $first,$second,$third..........$twentieth
The problem here is that i have to pass a variable to be used in the code below in a array and if i do so, the variable in the array acts like a variable itself.
foreach($id1 as $nexta)
$first = $nexta->get_content();
foreach($id2 as $nexta)
foreach($id3 as $nexta)
$third = $nexta->get_content();
foreach($id4 as $nexta)
$fourth = $nexta->get_content();
How do i make this code short and work ?