Loop through the array with for .
Print the current and current plus one value at each iteration using a counter.
Counter increase.
<?php $arr = array('a', 'b', 'c', 'd','e','f'); $i=0; $len = count($arr); for ($i=0; $i< $len; $i++) { // We could have used count($arr) //instead of $len. But, it will lead to //multiple calls to count() function causing code run slowly. echo "<br/>".$arr[$i] . '-' . $arr[$i+1]; ++$i; } ?>
source share