PHP小白入门到实战(一)核心语法

2020-03-28  本文已影响0人  简简天天

初识别PHP

What is PHP? 什么是PHP?
image.png
How Does PHP Work? PHP工作流程
image.png
image.png
Why Use PHP?为什么使用PHP?
image.png
What Can PHP Do?PHP能做什么?
image.png
What Can You Build? PHP开发人员能够制作什么作品?
image.png

PHP环境的安装

image.png

PHP变量(variables)及数据类型

image.png
image.png
image.png
image.png

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

PHP条件及运算符

image.png
image.png

短路现象&&和||

PHP数组
image.png
image.png

循环loops

image.png
image.png
image.png
image.png
image.png
image.png

使用频率:foreach>for>while>do while

PHP中的函数

image.png

字符串函数

// substr返回字符串的一部分
    echo substr('Hello',1).PHP_EOL;// ello
    echo substr('Hello',  1, 2).PHP_EOL; // el
    echo substr('Hello', -2); // lo
// 过滤掉数组中非字符串的值
$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
$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
(
)

上一篇 下一篇

猜你喜欢

热点阅读