PHP小白入门到实战(一)核心语法
2020-03-28 本文已影响0人
简简天天
初识别PHP
What is PHP? 什么是PHP?

How Does PHP Work? PHP工作流程


Why Use PHP?为什么使用PHP?

What Can PHP Do?PHP能做什么?

What Can You Build? PHP开发人员能够制作什么作品?

PHP环境的安装

PHP变量(variables)及数据类型




常量,第三个参数默认为false,修改为true的话,echo GREETING;和echo greeting;都可以正常解析
PHP条件及运算符


短路现象&&和||
PHP数组


循环loops






使用频率:foreach>for>while>do while
PHP中的函数

-
无返回值无参数
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