Let’s say I have this foreach loop:
foreach ($lists as $list) {
if (next list item == "test") {
echo "the next $list item equals 'test'";
}
}
I hope you get what i’m aiming at from the code.
Thanks,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
next().Bear in mind this advances the internal pointer, so to rewind it back, use
prev().However, in the example below, I used
current()which gets the current pointer of an array.foreach()seems to increment it once in the body of the construct.Konforce came up with this idea originally.
The last blank is
NULL, which is good (there is no next member). 🙂Output
CodePad.