php基础语法

PHP 是一种流行的服务器端脚本语言,用于开发动态网页和 Web 应用程序。

// 单行注释

/*
多行注释
*/

变量

$variable_name = value;

数据类型

  • 字符串:"Hello, World!"'123'
  • 整数:123-45
  • 浮点数:3.142.718
  • 布尔值:truefalse
  • 数组:$array = array(1, 2, 3);
  • 对象:$object = new ClassName();
  • NULL 值:null

4. 运算符

  • 算术运算符:+-*/%
  • 比较运算符:==!=<><=>=
  • 逻辑运算符:&&||!

5. 控制结构

条件语句
if (condition) {
    // code block to be executed if condition is true
} elseif (another_condition) {
    // code block to be executed if another_condition is true
} else {
    // code block to be executed if all conditions are false
}
循环结构
for ($i = 0; $i < 5; $i++) {
    // code block to be executed repeatedly until condition is false
}

while (condition) {
    // code block to be executed as long as condition is true
}

foreach ($array as $value) {
    // code block to be executed for each element in the array 
}

. 函数

function functionName($param1, $param2) {
    // function body with parameters and return statement if needed 
}

包含文件和引入文件内容:

include 'filename.php';   #包含并运行指定文件中的代码。
require 'filename.php';   #引入并运行指定文件中的代码,如果有错误则停止执行。
include_once 'filename.php'; #只包含一次指定文件中的代码。
require_once 'filename.php'; #只引入一次指定文件中的代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值