How do I generate $i
so that the first foreach
fills $artRows
like this:array(1 => array(2, 'id1', 'title1'), 2 => array(2, 'id2', 'title2'), 3 => ...);
And the second foreach
is of the same type, only its first iteration should continue the account $ i, as if to start adding elements to the end.
$artRows = array(); foreach ($rows2 as $row2) { $artRows[$i]['tbl'] = 2; $artRows[$i]['id'] = $row2['id']; $artRows[$i]['title'] = $row2['title']; } foreach ($rows as $row) { $artRows[$i]['tbl'] = 1; $artRows[$i]['id'] = $row['id']; $artRows[$i]['title'] = $row['title']; }
(1 => ['id' = 1, 'title' = '1'], 2 => ['id' = 2, 'title' = '2']);
- Makarenko_I_Vfor
where in one array it will be added with the index$i
, and in the other$i + count($arr1) - 1;
Although sure you can still do something easier, depending on the task .... I am sure you are building a crutch - Alexey Shimansky