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

Home php教程 php手冊 第三章 php操作符與控制結(jié)構(gòu)代碼

第三章 php操作符與控制結(jié)構(gòu)代碼

Jun 13, 2016 pm 12:03 PM
php one and code use the difference pair copy string quotation marks control insert operate third chapter structure

一.字符串插入
雙引號與單引號的區(qū)別:
1.雙引號的使用:

復制代碼 代碼如下:



//雙引號可以解析變量和轉(zhuǎn)義字符
$username = "jack";
echo "his name is $username!";
echo "
";
$username = "小東";
//如果是英文的感嘆號會正常解析變量
echo "他的名字是$username!";//他的名字是小東!
echo "
";
//如果是中文的感嘆號則會解析不出來
echo "他的名字是$username!";//他的名字是
echo "
";
//轉(zhuǎn)義字符在這里雖然被解析出來了,但是\n是在源代碼里換行
//瀏覽器顯示只是一個字符的位置
echo "他的名字是$username,\n他今年20歲了";//他的名字是小東, 他今年20歲了
echo "
";
//為了避免出現(xiàn)錯誤,推薦使用字符串連接的方式
echo "他的名字是".$username.",他今年20歲了";//他的名字是小東,他今年20歲了
?>


2.單引號的使用:

復制代碼 代碼如下:


//單引號只是輸出字符串字面值,
//不會解析變量和轉(zhuǎn)義字符。
//也不會進行語法加亮提示
$username = 'anllin';
echo 'his name is $username,\n his age is 20.';
//output
//his name is $username,\n his age is 20.
?>


部分常用的轉(zhuǎn)義字符

轉(zhuǎn)義序列

描述

\n

換行符

\r

回車

\t

水平制表圖

\\

反斜杠

\$

美元符

\”

雙引號


二.操作符

復制代碼 代碼如下:


//算術(shù)操作符
$a = 5;
$b = 3;
echo $a + $b;
echo '
';
echo $a - $b;
echo '
';
echo $a * $b;
echo '
';
echo $a / $b;
echo '
';
echo $a % $b;
?>


8
2
15
1.66666666667
2

復制代碼 代碼如下:


//復合賦值操作符
$a = 5;
$b = 3;
echo $a += $b;
echo '
';
echo $a -= $b;
echo '
';
echo $a *= $b;
echo '
';
echo $a /= $b;
echo '
';
echo $a %= $b;
echo '
';
echo $a .= $b;
?>


8
5
15
5
2
23

復制代碼 代碼如下:


//遞增遞減運算符
$a = 5;
echo ++$a;
echo '
';
echo $a++;
echo '
';
echo --$a;
echo '
';
echo $a--;
?>


6
6
6
6

復制代碼 代碼如下:


$a = 5;
$b = 3;
$c = 5;
$d = '5';
echo $a == $c;
echo '
';
echo $a === $c;
echo '
';
echo $a == $d;
echo '
';
echo $a != $b;
echo '
';
echo $a !== $d;
echo '
';
echo $a != $b;
echo '
';
echo $a > $b;
echo '
';
echo $b echo '
';
echo $a >= $c;
echo '
';
echo $a ?>


1
1
1
1
1
1
1
1
1
1

復制代碼 代碼如下:


$a = false;
echo ! $a;
echo '
';
$b = 5;
$c = 3;
echo $b > 0 && $c > 0;
echo '
';
echo $b > 0 and $c > 0;
echo '
';
echo $b != 0 || $c != 0;
echo '
';
echo $b != 0 or $c != 0;
echo '
';
?>


1
1
1
1
1
運算符”and”和”or”比&&和||的優(yōu)先級要低
三元操作符

復制代碼 代碼如下:


$a = 100;
echo $a > 60 ? 'success':'fail';
?>


success
錯誤抑制操作符

復制代碼 代碼如下:


echo @(100/0);
?>


?

?

三.控制結(jié)構(gòu)
If條件判斷語句

復制代碼 代碼如下:



$a = 10;
if ($a > 0)
{
echo '整數(shù)大于零';
}
echo '
';
if ($a > 0)
{
echo '整數(shù)大于零';
}
else if($a {
echo '整數(shù)小于零';
}
else
{
echo '整數(shù)等于零';
}
?>


Switch語句

復制代碼 代碼如下:



$role = 'admin';
switch ($role)
{
case 'admin' :
echo '管理員';
break;
case 'user' :
echo '普通用戶';
break;
case 'guest' :
echo '游客';
break;
default :
echo '游客';
break;
}
?>


While循環(huán)語句

復制代碼 代碼如下:


$a = 10;
while ( $a > 0 )
{
echo $a --;
echo '
';
}
?>


Do while 循環(huán)語句

復制代碼 代碼如下:


$a = 10;
do
{
echo $a --;
echo '
';
}
while ( $a > 0 )
?>


For循環(huán)語句

復制代碼 代碼如下:


for($a = 0; $a {
echo $a;
echo '
';
}
?>


Break語句

復制代碼 代碼如下:



for($a = 0; $a {
echo $a;
echo '
';
if($a ==5)
{
break;//終止循環(huán),但執(zhí)行循環(huán)后面的語句
}
}
echo '循環(huán)結(jié)束';
?>


Exit語句

復制代碼 代碼如下:


for($a = 0; $a {
echo $a;
echo '
';
if($a ==5)
{
exit;//直接退出,循環(huán)后面的語句不執(zhí)行
}
}
echo '循環(huán)結(jié)束';
?>


Continue語句

復制代碼 代碼如下:


for($a = 0; $a {
echo $a;
echo '
';
if($a ==5)
{
continue;//結(jié)束本次循環(huán),繼續(xù)下次循環(huán),循環(huán)后面的語句依然執(zhí)行
}
}
echo '循環(huán)結(jié)束';
?>

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)

Your First PHP Script: A Practical Introduction Your First PHP Script: A Practical Introduction Jul 16, 2025 am 03:42 AM

How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.

What is PHP and What is it Used For? What is PHP and What is it Used For? Jul 16, 2025 am 03:45 AM

PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

How Do You Handle File Operations (Reading/Writing) in PHP? How Do You Handle File Operations (Reading/Writing) in PHP? Jul 16, 2025 am 03:48 AM

TohandlefileoperationsinPHP,useappropriatefunctionsandmodes.1.Toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline-by-lineprocessing.2.Towritetoafile,usefile_put_contents()forsimplewritesorappendingwiththeFILE_APPENDflag,orfwrite()w

Which is better, DAI or USDC?_Is DAI suitable for long-term holding? Which is better, DAI or USDC?_Is DAI suitable for long-term holding? Jul 15, 2025 pm 11:18 PM

Is DAI suitable for long-term holding? The answer depends on individual needs and risk preferences. 1. DAI is a decentralized stablecoin, generated by excessive collateral for crypto assets, suitable for users who pursue censorship resistance and transparency; 2. Its stability is slightly inferior to USDC, and may experience slight deansal due to collateral fluctuations; 3. Applicable to lending, pledge and governance scenarios in the DeFi ecosystem; 4. Pay attention to the upgrade and governance risks of MakerDAO system. If you pursue high stability and compliance guarantees, it is recommended to choose USDC; if you attach importance to the concept of decentralization and actively participate in DeFi applications, DAI has long-term value. The combination of the two can also improve the security and flexibility of asset allocation.

PHP 8 Installation Guide PHP 8 Installation Guide Jul 16, 2025 am 03:41 AM

The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.

python if else example python if else example Jul 15, 2025 am 02:55 AM

The key to writing Python's ifelse statements is to understand the logical structure and details. 1. The infrastructure is to execute a piece of code if conditions are established, otherwise the else part is executed, else is optional; 2. Multi-condition judgment is implemented with elif, and it is executed sequentially and stopped once it is met; 3. Nested if is used for further subdivision judgment, it is recommended not to exceed two layers; 4. A ternary expression can be used to replace simple ifelse in a simple scenario. Only by paying attention to indentation, conditional order and logical integrity can we write clear and stable judgment codes.

Is USDC safe? What is the difference between USDC and USDT Is USDC safe? What is the difference between USDC and USDT Jul 15, 2025 pm 11:48 PM

USDC is safe. It is jointly issued by Circle and Coinbase. It is regulated by the US FinCEN. Its reserve assets are US dollar cash and US bonds. It is regularly audited independently, with high transparency. 1. USDC has strong compliance and is strictly regulated by the United States; 2. The reserve asset structure is clear, supported by cash and Treasury bonds; 3. The audit frequency is high and transparent; 4. It is widely accepted by institutions in many countries and is suitable for scenarios such as DeFi and compliant payments. In comparison, USDT is issued by Tether, with an offshore registration location, insufficient early disclosure, and reserves with low liquidity assets such as commercial paper. Although the circulation volume is large, the regulatory recognition is slightly low, and it is suitable for users who pay attention to liquidity. Both have their own advantages, and the choice should be determined based on the purpose and preferences of use.

Understand in one article: What does stablecoin mean Understand in one article: What does stablecoin mean Jul 15, 2025 pm 07:12 PM

Stable coins are cryptocurrencies with stable value. They maintain price stability by anchoring assets such as the US dollar to solve the volatility problem of crypto markets. Its core role includes providing a medium of transaction, a store of value and an account unit, supporting daily payment and safe-haven needs. There are three main types: 1. Frax (such as USDT and USDC), with a simple mechanism but dependent on centralized institutions; 2. Crypto Assets (such as DAI), with a high degree of decentralization but requiring over-collateralization; 3. Algorithm (such as Frax), which relies on smart contracts to adjust supply, but has a high risk. Stablecoins have become the cornerstone of the DeFi ecosystem and have shown great potential in fields such as cross-border payments.

See all articles