PHP foreach print array with previous and next element?

You could go: $data = array (1,2,3,4,5,6,7,8); $count = count ($data); foreach ($data as $key => $current) { if (($key - 1) ($count - 1)) { $next = $data0; } else { $next = $data$key + 1; } echo $prev . ', ' . $current .', ' .

$next . "\n"; Or if brevity is an issue: $count = count ($data); foreach ($data as $i => $current) { $prev = $data(($i - 1) ($count - 1))?0 : ($i + 1); echo $prev .',' . $current .

',' . $next . "\n"; }.

This solution assumes an array with numeric index and no holes. – zrvan Nov 24 '11 at 10:35.

$number) { $previous = $data($count+$index-1) % $count; // '$count+...' avoids problems // with modulo on negative numbers in PHP $current = $number; $next = $data($index+1) % $count; echo $previous. ", ". $current.", ".

$next. "\n"; } About modulo on negative numbers: mindspill.net/computing/cross-platform-n....

$data$count-$i-1:$data$i+1. ''; } echo $ret;? > Result: 16,1,2 1,2,3 2,3,4 3,4,5 4,5,6 5,6,7 6,7,8 7,8,9 8,9,10 9,10,11 10,11,12 11,12,13 12,13,14 13,14,15 14,15,16 15,16,1.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions