Hello all I am trying to find a solution for joining multiple 'expr' together using for with 'count'.Whatever combination I use does not work.
Currently I have:
for($i=0; $i<14; $i++) {
//echo some values for the table;
}
//echo a table;
}
This sets the amount of values to be used in my tables.
But I have a two breaks where the numbers are missing so I need something like:
e.g 1:
//this gives syntax error
for($i=0; $i<2; $i=4; $i<8; $i=10; $i<15; $i++) {
//echo some values for the table;
}
//echo a table;
}
e.g 2:
//just doesnt work
for($i=0; $i<2; $i++) for($i=4; $i<8; $i++) for($i=10; $i<15; $i++) {
//echo some values for the table;
}
//echo a table;
}
e.g 3:
//breaks my table
for($i=0; $i<2; $i++);
for($i=4; $i<8; $i++);
for($i=10; $i<15; $i++) {
//echo some values for the table;
}
//echo a table;
}
e.g 4:
//this one is straight out of the php manual & doesnt work
for($i=0; $i<2; $i++) {
for($i=4; $i<8; $i++) {
for($i=10; $i<15; $i++) {
//echo some values for the table;
}
}
}
}
//echo a table;
}
Please can you help me I need to find a solution to this - many thanks.
Iterate over the numbers you expect by forming an array of them with array_merge()
and range()
:
// $i=0; $i<2; $i=4; $i<8; $i=10; $i<15
foreach( array_merge( range( 0, 2), range( 4, 8), range( 10, 15)) as $i) {
echo $i;
}
0 1 2 4 5 6 7 8 10 11 12 13 14 15
An alternative approach, you can form the range from 0 - 15
, then remove 3
and 9
and iterate (Here the values we are interested in are in the key of the array, and not the value):
$arr = array_flip(range( 0, 15));
unset($arr[3]);
unset($arr[9]);
foreach( $arr as $i => $garbage) {
echo $i . "
";
}
It produces the same output as above.