Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How many kinds of loop statements are there in php

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how many kinds of circular sentences in php, I believe most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

There are four kinds of loop statements. They are: 1, for loop, syntax "for (initial value; condition; added value) {loop body}"; 2, dowhile loop, syntax "do {loop body} while (condition)"; 3, while loop, syntax "while (condition) {loop body}"; 4, foreach loop.

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

There are several kinds of loop statements in php

In PHP, the following loop statements are provided:

1. While-executes the code block in a loop as long as the specified condition is true

2. Do...while-first execute the code block once, and then repeat the loop when the specified condition holds

3. For-the number of times that the code block is executed in a loop

4. Foreach-loops the code block based on each element in the array

Examples are as follows:

For cycle

Grammar rules:

For (initialization count initial value; judgment condition; increase count value) {loop body;}

While cycle

rule of grammar

While (judgment condition) {cyclic body;}

The while cycle first judges the cycle conditions, and then carries on the cycle. When the conditions are not met, jump out of the cycle.

Do while cycle

rule of grammar

Do {cyclic body;} while (judgment condition)

The do while loop first enters the loop and judges the conditions of the loop. So no matter whether the judgment condition is true or false, there is at least one cycle.

Foreach cycle

rule of grammar

Foreach ($array as $value) {execute code;}

Or

Foreach ($array as $key = > $value) {execute code;}

$array: array $value: array key value $key: array key name.

Foreach is used for array traversal. Loop one at a time so that the current value is assigned to the $value variable, and the array pointer moves one by one to the last element.

The above is all the contents of the article "how many kinds of cyclic sentences are there in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report