My code is
<?php
$colors = array("red", "green", "blue", "yellow", "violet");
$i=0;
foreach ($colors as $value) {
echo "$value.$i <br>";
$i++;
}
?>
gives a result as
red.0
green.1
blue.2
yellow.3
violet.4
Now I want my result to be like this
section
red.0
green.1
section
blue.2
yellow.3
section
violet.4
adding a value after each two rows until my array finishes.? How can I get this done ? thanks in advance.
I try the code with two foreach loop is
$i = 0;
foreach ($strData->body as $ins) {
$items = [];
if ($i % 2 == 0) {
// We will echo section at the first iteration and every multiple of 2 now.
fwrite($fp, str_replace('</pre>','', str_replace('<pre >','',''. $finalHead . $table->getTable() )));
}
foreach ($ins as $key=>$value) {
//echo "-----".$value."-----";
array_push($items,$value);
}
$table->addRow($items);
$i++;
}
result is
** ADT PLASTIC ** STATEMENT as on 12/08/2021
--------------
** ADT PLASTIC ** STATEMENT as on 12/08/2021
----------------------------
CC Limit 1,000
Availed Limit 10,621
** ADT PLASTIC ** STATEMENT as on 12/08/2021
-----------------------------
CC Limit 1,000
Availed Limit 10,621
PM Stock Value 75,095
RM Stock Value 67,895
** ADT PLASTIC ** STATEMENT as on 12/08/2021
----------------------------------
CC Limit 1,000
Availed Limit 10,621
PM Stock Value 75,095
RM Stock Value 67,895
Product Stock Value 46,456
Total Stock Value 1,446
*Report taken by NATH on 19/08/2021 at 04:08:34 in TESTER *
Actualy I want that heading only after each two rows only. Where am wrong ?