Home Backend Development PHP Tutorial Learn more about php4(1)--Back to the Future_PHP Tutorial

Learn more about php4(1)--Back to the Future_PHP Tutorial

Jul 21, 2016 pm 04:05 PM
learn cycle yes future concept go deep of able repeat

For those readers who are unfamiliar with this concept, a loop is a control structure that allows you to reuse the same series of PHP commands over and over again. The actual number of repetitions can be decided by you.

The first and simplest loop is the so-called "while" loop, as shown below:

while (condition)
{
do this!
}

Or, in Chinese

while (it’s raining)
{
Bring an umbrella!
}

In this case , as long as the value of the condition is true, remember what you learned last time? ---The PHP commands in curly brackets will always be executed. As soon as the condition becomes false - for example, in the above example, the sun comes out, the loop will terminate and subsequent commands will not be executed.

Here is a simple example to illustrate how to use a "while" loop:



< ?

// If the form has not been submitted yet, Display initialization page
if (!$submit)
{
?>

< html>

< head>
< /head>

< body>
< h2>Incredibly wonderful time machine< /h2>
< form action="tmachine.php" method ="POST">
In which year do you plan to visit?
< input type="text" name="year" size="4" maxlength="4">
< input type="submit" name="submit" value="Go">
< /form>
< /body>
< /html>

< ?
}
else
// Otherwise, it will be processed and a new page will be generated
{
?>

< html>

< head>
< /head>

< body>

< ?
//The current year
$current = 2001;

// Check the future time and generate the corresponding information


In this example, we first ask the user for the year he wishes to access - the year is stored in the variable year , and sent to the PHP script.

The script first checks the year to make sure it is in the past [haha, we seem to be doing this ourselves now] and then uses a "while" loop to calculate backwards from the current year - 2001 and store the result in the variable current until the values ​​of $current and $year are the same.

Please note that we use the submit variable to generate both an initialization form and a processing page on the same PHP page - we have already explained this technology to you in detail last time.​

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315766.htmlTechArticleFor those readers who are not familiar with this concept, a loop is a method that allows you to reuse the same series over and over again Control structure of PHP commands. The actual number of repetitions can be decided by you. ...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does the metaverse concept mean? What is the metaverse concept? What does the metaverse concept mean? What is the metaverse concept? Feb 22, 2024 pm 03:55 PM

The Metaverse is an illusory world that uses technology to map and interact with the real world. Analysis 1 Metaverse [Metaverse] is an illusory world that makes full use of technological methods to link and create, and maps and interacts with the real world. It is a data living space with the latest social development system. The 2-dimensional universe is essentially a virtual technology and digital process of the real world, which requires a lot of transformation of content production, economic system, customer experience and physical world content. 3 However, the development trend of the metaverse is gradual. It is finally formed by the continuous combination and evolution of many tools and platforms with the support of shared infrastructure, standards and protocols. Supplement: What is the metaverse composed of? 1 The metaverse is composed of Meta and Verse, Meta is transcendence, and V

At a glance: A quick overview of how to open JSP files At a glance: A quick overview of how to open JSP files Jan 31, 2024 pm 09:28 PM

JSP file opening method JSP (JavaServerPages) is a dynamic web page technology that allows programmers to embed Java code in HTML pages. JSP files are text files that contain HTML code, XML tags, and Java code. When a JSP file is requested, it is compiled into a JavaServlet and then executed by the web server. Methods of Opening JSP Files There are several ways to open JSP files. The easiest way is to use a text editor,

Introduction and core concepts of Oracle RAC Introduction and core concepts of Oracle RAC Mar 07, 2024 am 11:39 AM

Introduction and core concepts of OracleRAC (RealApplicationClusters) As the amount of enterprise data continues to grow and the demand for high availability and high performance becomes increasingly prominent, database cluster technology becomes more and more important. OracleRAC (RealApplicationClusters) is designed to solve this problem. OracleRAC is a high-availability, high-performance cluster database solution launched by Oracle.

Lambda expression breaks out of loop Lambda expression breaks out of loop Feb 20, 2024 am 08:47 AM

Lambda expression breaks out of the loop, specific code examples are needed. In programming, the loop structure is an important syntax that is often used. However, in certain circumstances, we may want to break out of the entire loop when a certain condition is met within the loop body, rather than just terminating the current loop iteration. At this time, the characteristics of lambda expressions can help us achieve the goal of jumping out of the loop. Lambda expression is a way to declare an anonymous function, which can define simple function logic internally. It is different from an ordinary function declaration,

How to extract only one piece of duplicate data in Oracle database? How to extract only one piece of duplicate data in Oracle database? Mar 09, 2024 am 09:03 AM

How to extract only one piece of duplicate data in Oracle database? In daily database operations, we often encounter situations where we need to extract duplicate data. Sometimes we want to find one of the duplicate data instead of listing all the duplicate data. In Oracle database, we can achieve this purpose with the help of some SQL statements. Next, we will introduce how to extract only one piece of duplicate data from the Oracle database and provide specific code examples. 1. Use ROWID function ROWID is Ora

What are the alternatives to recursive calls in Java functions? What are the alternatives to recursive calls in Java functions? May 05, 2024 am 10:42 AM

Replacement of recursive calls in Java functions with iteration In Java, recursion is a powerful tool used to solve various problems. However, in some cases, using iteration may be a better option because it is more efficient and less prone to stack overflows. Here are the advantages of iteration: More efficient since it does not require the creation of a new stack frame for each recursive call. Stack overflows are less likely to occur because stack space usage is limited. Iterative methods as an alternative to recursive calls: There are several methods in Java to convert recursive functions into iterative functions. 1. Use the stack Using the stack is the easiest way to convert a recursive function into an iterative function. The stack is a last-in-first-out (LIFO) data structure, similar to a function call stack. publicintfa

What is the Oracle home directory? Detailed explanation of the concept and function of Oracle home directory What is the Oracle home directory? Detailed explanation of the concept and function of Oracle home directory Mar 08, 2024 am 08:18 AM

Title: Oracle Master Catalog: Concepts, Functions and Code Examples The master catalog (MasterCatalog) in the Oracle database is the basic directory structure of the database and is used to store metadata about database objects and other database information. The home directory plays the role of the management center of the database, recording information about all objects in the database, such as tables, indexes, views, users, etc., and also includes database configuration information and permission information. In Oracle database, the concept of home directory is very important, it is used

PHP returns all the values ​​in the array to form an array PHP returns all the values ​​in the array to form an array Mar 21, 2024 am 09:06 AM

This article will explain in detail how PHP returns all the values ​​of an array to form an array. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Using the array_values() function The array_values() function returns an array of all the values ​​in an array. It does not preserve the keys of the original array. $array=[&quot;foo&quot;=&gt;&quot;bar&quot;,&quot;baz&quot;=&gt;&quot;qux&quot;];$values=array_values($array);//$values ​​will be [&quot;bar&quot;,&quot;qux&quot;]Using a loop can Use a loop to manually get all the values ​​of the array and add them to a new

See all articles