I have a simple foreach loop which enters data in a 2D array:
foreach ($query as $row){
if (!isset($sites[$row->site])){ $sites[$row->site] = array(); }
if (!isset($sites2[$row->site])){ $sites2[$row->site] = array(); }
if ($row->type == 1){
$sites[$row->site][] = array($row->data1, $row->data2);
} else {
$sites2[$row->site][] = array($row->data1, $row->data2);
}
}
I need a minimum of 20 entries in the array’s ($sites and $sites2).
So if the query has lets say 5 rows, I want to reiterate the loop, repeating the 5 existent rows (inserting them inside the arrays) until the arrays reach 20 rows.
Any ideas?
try this: