1. 運(yùn)算符
PHP 中的運(yùn)算符分為:算術(shù)運(yùn)算符、遞增/遞減運(yùn)算符只洒、比較運(yùn)算符许帐、邏輯運(yùn)算符、數(shù)組運(yùn)算符毕谴、三元運(yùn)算符等成畦。
1.1 算術(shù)運(yùn)算符
注意連接字符串的并置運(yùn)算符,a .= b 等同于 a = a.b涝开。
1.2 邏輯運(yùn)算符
- x and y
- x or y
- x xor y
1.3 數(shù)組運(yùn)算符
數(shù)組運(yùn)算符.png
2. 數(shù)組
在 PHP 中循帐,array() 函數(shù)用于創(chuàng)建數(shù)組。
2.1 有三種類型的數(shù)組:
- 數(shù)值數(shù)組
- 關(guān)聯(lián)數(shù)組
- 多維數(shù)組
2.2 獲取數(shù)組長度
count() 函數(shù)用于返回?cái)?shù)組的長度舀武。
2.3 關(guān)聯(lián)數(shù)組
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
或者:
$age['Peter']="35";
$age['Ben']="37";
$age['Joe']="43";
2.3.1 遍歷關(guān)聯(lián)數(shù)組
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
foreach的兩種語法
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement
2.4 數(shù)組排序
image.png