PHP小白入门到实战(一)核心语法
2020-03-28 本文已影响0人
简简天天
初识别PHP
What is PHP? 什么是PHP?
![](https://img.haomeiwen.com/i2294180/f04e5fcac01ab07f.png)
How Does PHP Work? PHP工作流程
![](https://img.haomeiwen.com/i2294180/24d6eefef00fd2ac.png)
![](https://img.haomeiwen.com/i2294180/92b12f94e26f81d8.png)
Why Use PHP?为什么使用PHP?
![](https://img.haomeiwen.com/i2294180/c7f47888b1e2b0e2.png)
What Can PHP Do?PHP能做什么?
![](https://img.haomeiwen.com/i2294180/bd18704941aaed66.png)
What Can You Build? PHP开发人员能够制作什么作品?
![](https://img.haomeiwen.com/i2294180/bd4a551eed681149.png)
PHP环境的安装
![](https://img.haomeiwen.com/i2294180/3f91e3bd98ad38a7.png)
PHP变量(variables)及数据类型
![](https://img.haomeiwen.com/i2294180/8e50e4baf3408716.png)
![](https://img.haomeiwen.com/i2294180/fc29a180871ff194.png)
![](https://img.haomeiwen.com/i2294180/b9f6b72a3e9c77a0.png)
![](https://img.haomeiwen.com/i2294180/6b2e6585e27f53aa.png)
常量,第三个参数默认为false,修改为true的话,echo GREETING;和echo greeting;都可以正常解析
PHP条件及运算符
![](https://img.haomeiwen.com/i2294180/925acf1dc2eb5a20.png)
![](https://img.haomeiwen.com/i2294180/8801a8433775a597.png)
短路现象&&和||
PHP数组
![](https://img.haomeiwen.com/i2294180/50ffefa682cb2e0f.png)
![](https://img.haomeiwen.com/i2294180/9a6ce3dc119e0bd7.png)
循环loops
![](https://img.haomeiwen.com/i2294180/d19ec904fa67896f.png)
![](https://img.haomeiwen.com/i2294180/2742c47862c32a50.png)
![](https://img.haomeiwen.com/i2294180/b4dfcdd2796c4cef.png)
![](https://img.haomeiwen.com/i2294180/409831a675bab622.png)
![](https://img.haomeiwen.com/i2294180/52caf233e89fed1e.png)
![](https://img.haomeiwen.com/i2294180/fc3edb68d8d57cf4.png)
使用频率:foreach>for>while>do while
PHP中的函数
![](https://img.haomeiwen.com/i2294180/7635a074c734dd74.png)
-
无返回值无参数
image.png
y
-
有参无返回值
image.png
-
有参有返回值
image.png
-
函数传引用,取地址符号&
image.png
字符串函数
- substr
// substr返回字符串的一部分
echo substr('Hello',1).PHP_EOL;// ello
echo substr('Hello', 1, 2).PHP_EOL; // el
echo substr('Hello', -2); // lo
-
strlen strpos strrpos trim
image.png
-
strtolower strtoupper ucwords
image.png
-
str_replace
-
is_string
image.png
// 过滤掉数组中非字符串的值
$values = [true,false,null,'abc',33,'33',22.4,'22.3','',' ',0,'0'];
foreach($values as $val){
if(is_string($val)){
echo $val.'is string'.PHP_EOL;
}
}
abcis string
33is string
22.3is string
is string
is string
0is string
- gzcompress gzuncompress 压缩解压缩字符串
$str = 'abcdefg';
$compressed = gzcompress($str);
echo $compressed.PHP_EOL;
$original = gzuncompress($compressed);
echo $original;
x�KLJNIMK�
���
abcdefg
数组函数
- 数组创建、添加、删除
#创建一个数组
$arr = array();
#添加内容到数组中,末尾添加
array_push($arr,'hello');
print_r($arr);
#添加内容到数组中,开头添加
array_unshift($arr, 'world');
print_r($arr);
#删除内容,末尾删除
array_pop($arr);
print_r($arr);
#删除内容,开头删除
array_shift($arr);
print_r($arr);
Array
(
[0] => hello
)
Array
(
[0] => world
[1] => hello
)
Array
(
[0] => world
)
Array
(
)
-
数组排序sort 数组和字符串相互转换implode、explode
image.png