国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
目錄
條件語(yǔ)句
if語(yǔ)句
switch語(yǔ)句
循環(huán)語(yǔ)句
while循環(huán)
do…while循環(huán)
for循環(huán)
foreach循環(huán)
Home Backend Development PHP Tutorial 前端學(xué)PHP之話語(yǔ)

前端學(xué)PHP之話語(yǔ)

Jun 13, 2016 pm 12:28 PM
echo foreach gt while

前端學(xué)PHP之語(yǔ)句

目錄
[1]條件語(yǔ)句 if語(yǔ)句 switch語(yǔ)句 [2]循環(huán)語(yǔ)句 while循環(huán) do…while循環(huán) for循環(huán) foreach循環(huán)

條件語(yǔ)句

  用于基于不同條件執(zhí)行不同的動(dòng)作

if語(yǔ)句

<span style="color: #0000ff;">if</span><span style="color: #000000;"> (條件) {  當(dāng)條件為 </span><span style="color: #0000ff;">true</span><span style="color: #000000;"> 時(shí)執(zhí)行的代碼;}</span>
<span style="color: #0000ff;">if</span><span style="color: #000000;"> (條件) {  條件為 </span><span style="color: #0000ff;">true</span><span style="color: #000000;"> 時(shí)執(zhí)行的代碼;} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {  條件為 </span><span style="color: #0000ff;">false</span><span style="color: #000000;"> 時(shí)執(zhí)行的代碼;}</span>
<span style="color: #0000ff;">if</span><span style="color: #000000;"> (條件) {  條件為 </span><span style="color: #0000ff;">true</span><span style="color: #000000;"> 時(shí)執(zhí)行的代碼;} elseif (條件) {  條件為 </span><span style="color: #0000ff;">true</span><span style="color: #000000;"> 時(shí)執(zhí)行的代碼;} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {  條件為 </span><span style="color: #0000ff;">false</span><span style="color: #000000;"> 時(shí)執(zhí)行的代碼;}</span>
<span style="color: #000000;">php</span><span style="color: #800080;">$t</span>=<span style="color: #008080;">date</span>("H"<span style="color: #000000;">);</span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$t</span>) {  <span style="color: #0000ff;">echo</span> "Have a good morning!"<span style="color: #000000;">;} </span><span style="color: #0000ff;">elseif</span> (<span style="color: #800080;">$t</span>) {  <span style="color: #0000ff;">echo</span> "Have a good day!"<span style="color: #000000;">;} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {  </span><span style="color: #0000ff;">echo</span> "Have a good night!"<span style="color: #000000;">;}</span>?>

?

switch語(yǔ)句

<span style="color: #0000ff;">switch</span><span style="color: #000000;"> (expression){</span><span style="color: #0000ff;">case</span> label1:<span style="color: #000000;">  code to be executed </span><span style="color: #0000ff;">if</span> expression =<span style="color: #000000;"> label1;  </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;  </span><span style="color: #0000ff;">case</span> label2:<span style="color: #000000;">  code to be executed </span><span style="color: #0000ff;">if</span> expression =<span style="color: #000000;"> label2;  </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #0000ff;">default</span>:<span style="color: #000000;">  code to be executed  </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> expression is different   from both label1 and label2;}</span>
<span style="color: #000000;">php</span><span style="color: #0000ff;">switch</span> (<span style="color: #800080;">$x</span><span style="color: #000000;">){</span><span style="color: #0000ff;">case</span> 1:  <span style="color: #0000ff;">echo</span> "Number 1"<span style="color: #000000;">;  </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #0000ff;">case</span> 2:  <span style="color: #0000ff;">echo</span> "Number 2"<span style="color: #000000;">;  </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #0000ff;">case</span> 3:  <span style="color: #0000ff;">echo</span> "Number 3"<span style="color: #000000;">;  </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #0000ff;">default</span>:  <span style="color: #0000ff;">echo</span> "No number between 1 and 3"<span style="color: #000000;">;}</span>?>

?

循環(huán)語(yǔ)句

  在編寫代碼時(shí),經(jīng)常需要反復(fù)運(yùn)行同一代碼塊,可以使用循環(huán)來(lái)執(zhí)行這樣的任務(wù)

while循環(huán)

<span style="color: #0000ff;">while</span><span style="color: #000000;"> (條件為真) {  要執(zhí)行的代碼;}</span>
<span style="color: #000000;">php</span><span style="color: #800080;">$sum</span> = 12;<span style="color: #008000;">//</span><span style="color: #008000;">小寵物當(dāng)前的饑餓程度</span><span style="color: #0000ff;">echo</span> "我餓啦:-("<span style="color: #000000;">;</span><span style="color: #0000ff;">echo</span> "<br>"<span style="color: #000000;">;</span><span style="color: #0000ff;">while</span>(<span style="color: #800080;">$sum</span>){<span style="color: #008000;">//</span><span style="color: #008000;">小寵物的饑餓程度到100,表示小寵物吃飽啦,不用繼續(xù)喂了,沒吃飽繼續(xù)喂食</span>    <span style="color: #800080;">$num</span> = <span style="color: #008080;">rand</span>(1,20);<span style="color: #008000;">//</span><span style="color: #008000;">隨機(jī)數(shù),模擬喂食小寵物的小面包</span>  <span style="color: #800080;">$sum</span> = <span style="color: #800080;">$sum</span> + <span style="color: #800080;">$num</span>; <span style="color: #008000;">//</span><span style="color: #008000;">小寵物吃小面包</span>  <span style="color: #0000ff;">echo</span> "我還沒吃飽呢!"<span style="color: #000000;">;  </span><span style="color: #0000ff;">echo</span> "<br>"<span style="color: #000000;">;}</span><span style="color: #0000ff;">echo</span> "終于吃飽啦^_^"<span style="color: #000000;">;</span>?>

?

do…while循環(huán)

  循環(huán)首先會(huì)執(zhí)行一次代碼塊,然后檢查條件,如果指定條件為真,則重復(fù)循環(huán)

<span style="color: #0000ff;">do</span><span style="color: #000000;"> {  要執(zhí)行的代碼;} </span><span style="color: #0000ff;">while</span> (條件為真);
<span style="color: #000000;">php  </span><span style="color: #800080;">$sum</span>  = 0<span style="color: #000000;">;   </span><span style="color: #0000ff;">do</span><span style="color: #000000;">{    </span><span style="color: #800080;">$num</span> = <span style="color: #008080;">rand</span>(1,6);<span style="color: #008000;">//</span><span style="color: #008000;">獲取1至6的隨機(jī)數(shù),模擬擲骰子</span>    <span style="color: #800080;">$sum</span> = <span style="color: #800080;">$sum</span>  + <span style="color: #800080;">$num</span>;<span style="color: #008000;">//</span><span style="color: #008000;">前進(jìn)步長(zhǎng)</span>  }<span style="color: #0000ff;">while</span>(<span style="color: #800080;">$num</span>==6<span style="color: #000000;">);  </span><span style="color: #0000ff;">echo</span> "do...while例子執(zhí)行完畢,前進(jìn):".<span style="color: #800080;">$sum</span> ."<br>"<span style="color: #000000;">;</span>?>

?

for循環(huán)

  for循環(huán)語(yǔ)句中,初始化在循環(huán)開始前無(wú)條件求值一次,循環(huán)條件在每次循環(huán)開始前求值。如果值為true,則繼續(xù)循環(huán),執(zhí)行循環(huán)體語(yǔ)句;如果值為false,則終止循環(huán)。遞增語(yǔ)句在每次循環(huán)后執(zhí)行

<span style="color: #0000ff;">for</span><span style="color: #000000;"> (init counter; test counter; increment counter) {  code to be executed;}    </span>
<span style="color: #000000;">php </span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$x</span>=0; <span style="color: #800080;">$x</span>$x++<span style="color: #000000;">) {  </span><span style="color: #0000ff;">echo</span> "數(shù)字是:<span style="color: #800080;">$x</span> <br>"<span style="color: #000000;">;} </span>?>

?

foreach循環(huán)

  foreach循環(huán)只適用于數(shù)組,用于遍歷數(shù)組中每個(gè)鍵/值對(duì)。每進(jìn)行一次循環(huán)迭代,當(dāng)前數(shù)組元素的值就會(huì)被賦值給$value變量,并且數(shù)組指針會(huì)逐一移動(dòng),直到到達(dá)最后一個(gè)數(shù)組元素。一般有兩種方式:不取下標(biāo)、取下標(biāo)

[1]只取值,不取下標(biāo)

<span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$array</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$value</span><span style="color: #000000;">) {  code to be executed;}    </span>
<span style="color: #000000;">php </span><span style="color: #800080;">$colors</span> = <span style="color: #0000ff;">array</span>("red","green","blue","yellow"<span style="color: #000000;">); </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$colors</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$value</span><span style="color: #000000;">) {  </span><span style="color: #0000ff;">echo</span> "<span style="color: #800080;">$value</span> <br>"<span style="color: #000000;">;}</span>?>

[2]同時(shí)取下標(biāo)和值

<span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$array</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$index</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) {  code to be executed;} </span>
<span style="color: #000000;">php </span><span style="color: #800080;">$colors</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(  </span>"r"=>"red",  "g"=>"green",  "b"=>"blue",  "y"=>"yellow"<span style="color: #000000;">); </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$colors</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) {  </span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$key</span>.":".<span style="color: #800080;">$value</span>."<br>"<span style="color: #000000;">;}</span>?>

?

1樓文昊學(xué)PHP
PHP是樓主接觸的第一個(gè)編程語(yǔ)言?
Re: 小火柴的藍(lán)色理想
@文昊學(xué)PHP,我學(xué)前端的,主要是js,PHP了解即可
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

In C language, what is the difference between while(1) and while(0)? In C language, what is the difference between while(1) and while(0)? Aug 31, 2023 am 10:45 AM

We know that in C language, 'while' keyword is used to define a loop that works based on the condition passed to the loop. Now, since the condition can have two values, true or false, the code inside the while block will be executed repeatedly if the condition is true and will not be executed if the condition is false. Now, by passing parameters to the while loop, we can differentiate between while(1) and while(0) because while(1) is a loop where the condition is always considered true and hence the code inside the block will start executing repeatedly. Furthermore, we can state that it is not 1 that is passed to the loop that makes the condition true, but if any non-zero integer is passed to the while loop, then it will be considered as the true condition, so

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? Apr 27, 2023 pm 03:40 PM

1. The difference between Iterator and foreach is the polymorphic difference (the bottom layer of foreach is Iterator) Iterator is an interface type, it does not care about the type of collection or array; both for and foreach need to know the type of collection first, even the type of elements in the collection; 1. Why is it said that the bottom layer of foreach is the code written by Iterator: Decompiled code: 2. The difference between remove in foreach and iterator. First, look at the Alibaba Java Development Manual, but no error will be reported in case 1, and an error will be reported in case 2 (java. util.ConcurrentModificationException) first

How to determine the number of foreach loop in php How to determine the number of foreach loop in php Jul 10, 2023 pm 02:18 PM

?The steps for PHP to determine the number of the foreach loop: 1. Create an array of "$fruits"; 2. Create a counter variable "$counter" with an initial value of 0; 3. Use "foreach" to loop through the array, and Increase the value of the counter variable in the loop body, and then output each element and their index; 4. Output the value of the counter variable outside the "foreach" loop to confirm which element the loop reaches.

PHP returns an array with key values ??flipped PHP returns an array with key values ??flipped Mar 21, 2024 pm 02:10 PM

This article will explain in detail how PHP returns an array after key value flipping. 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. PHP Key Value Flip Array Key value flip is an operation on an array that swaps the keys and values ??in the array to generate a new array with the original key as the value and the original value as the key. Implementation method In PHP, you can perform key-value flipping of an array through the following methods: array_flip() function: The array_flip() function is specially used for key-value flipping operations. It receives an array as argument and returns a new array with the keys and values ??swapped. $original_array=[

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

What are the most popular golang frameworks on the market? What are the most popular golang frameworks on the market? Jun 01, 2024 pm 08:05 PM

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ??are springing up like mushrooms after a rain. One of the languages ??that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

See all articles