php - Using next in foreach loop -


i looping through array using foreach.

in particular situation need know value of next element before iteration comes that(like prediction) element. planning use function next().

in documentation noticed next() advances internal array pointer forward.

next() behaves current(), 1 difference. advances internal array pointer 1 place forward before returning element value. means returns next array value , advances internal array pointer one.

if affect foreach loop?

it not affect loop if use in way

<?php  $lists = range('a', 'f');  foreach($lists &$value) {    $next = current($lists);    echo 'value: ' . $value . "\n" . 'next: ' . $next . "\n\n"; } 

output

value: next: b

value: b next: c

value: c next: d

value: d next: e

value: e next: f

value: f next:


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -