I've got an array. Below is an example
$arr = ["apple", "mango", "chair", "table", "pink", "red"];
I need to access 2 at a time within a for loop.
for ($i=0;$i<$arr.length;$i++){
$var = 'First item is '.$arr[$i].' and the second is '.$arr[$i+1];
}
The 1st output is First item is apple and the second is mango
.
But from the 2nd output is First item is mango and the second is chair
.
I want to output in pairs. So the expected outputs are:
First item is apple and the second is mango
First item is chair and the second is table
First item is pink and the second is red
how do I do this? And I want to add a <br>
tag at the end of each line except for the last.