CascadiaPHP 2024

Voting

: seven minus three?
(Example: nine)

The Note You're Voting On

Anonymous
2 years ago
This is the best example of using next in a loop

<?php
$array
= array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');

// this cycle echoes all associative array
// key where value equals "apple"
reset($array); // prepare array for cycle
while ($fruit_name = current($array)) {
if (
$fruit_name == 'apple') {
echo
key($array), "\n";
}
next($array);
}
reset($array);
?>

<< Back to user notes page

To Top -