How does php exit the foreach loop?

Source: Internet
Author: User
Php how to exit the foreach loop break; if the break is completed by function/method processing, you can also use returnreturnd for usage. refer to the following article, although Java is used, however, some PHP syntaxes are also applicable. Brief introduction to return and PHPcodeforeach in Java (how does $ dat php exit the foreach loop?
How does php exit the foreach loop break;

------ Solution --------------------
Break

If function/method processing ends, you can also use return

For returnd usage, refer to the following article. although Java is used, some PHP syntax is also applicable.
Brief introduction to return in Java
------ Solution --------------------
PHP code
Foreach ($ data as $ row) {echo $ row; break ;}
------ Solution --------------------
PHP code
Foreach ($ array as $ key => $ value) {if ($ value = 5) break;} // This is a type. // If it is a nested loop, you can add a number using continue to implement foreach ($ array as $ key => $ value) {foreach ($ value as $ key2 => $ value2) {if ($ value = 5) continue 2 ;}}
------ Solution --------------------
Break, continue, return, exit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.