Hi,
In Perl the "next" operator allows you to skip to the end of the current loop and starts the next iteration. For example in perl:
@array = (1,2,3,4);
foreach $element (@array) {
next if $element == 2;
print "$element\n";
Do more stuff
}
would print
1
3
4
The documentation for php says the next
function moves the the internal pointer of the array to the next element and returns that element or false. In PHP:
<?php
$array = array(1,2,3,4);
foreach ($array as $element) {
if ($element == 2) {
next($array);
}
print "$element\n";
}
?>
produces 1,2,3,4. Element 2 is not skipped.
It seems the PHP next function is not really the same thing as the next operator in Perl.
In PHP, how would one do something similar to the Perl next operator?
One simple method would be to enclose the echo statement in a "if" block. I would prefer not to do that if possible. I normally use the "next" operator to skip over elements in an array that I do not want to process.
Thanks,
Alana 🙂