PHP语法_基础_知识
1.echo() 函数 返回值:void
echo 表示向浏览器输出字符串
2.注释 // # /*......*/
3.print() ,printf() ,print_r()
print()函数 返回值:int;
表示向浏览器输出字符串
echo print("print");
输出结果: print1
echo 把print的返回值打印出来
printf()函数 返回字符串的长度;
(中文占两个)
printf("我今天买了%d套光盘",10);
输出结果:我今天买了10套光盘
sprintf()函数 字符串保留在内存中;
需要echo 将其输出
echo sprintf("123");
print_r() 函数打印变量本身;
如果是数组则打印出数组
$a=array('a','b','c','d');
print_r($a);
3.标示符与变量
标识符是变量名称
标识符可以任意长度,可以由任何字母,数字,下划线组成
标识符不能由数字开始
在PHP中标示符区分大小写
一个变量名称可以与一个函数名称相同
创建变量:$sum=0 ; $name="names";
通过赋值来确定变量类型
变量的类型:
PHP支持如下基本数据类型:
Integer,Float(Double),String,Boolean,Array,Object
类型转换:
$num=1;
$total=(float)$num;
*检查变量的类型
Gettype() 检测变量类型;
$a=3.14;
echo gettype($a);
输出结果: Double
Settype() 设置变量类型;
$sum=100;
settype($sum,"string");
echo gettype($sum);
输出结果: string
*检测变量是否存在
isset(); //判读变量是否存在
$a=1;
echo isset($a); //返回的是布尔值
如果$a存在返回 : 1
unset(); //销毁变量
unset($a);
销毁变量$a;
empty();
echo empty($a);
检查一个变量的值是否为空,为空就返回 1
类型判断函数
is_array(),is_double(),is_float(),is_real(),is_long(),
is_integer(),is_string(),is_object(),is_resource(),
is_null(),is_numeric()
$num=100;
is_interger($num);
变量数据类型转换函数(临时转换):
intval(),floatval(),strval()
$num=22.22;
$a=intval($num);
intval($num)整体被转换成整型
$num的类型没有改变
超级全局变量:
$GLOBALS [所有全局变量数组]
$_SERVER [服务器环境变量数组]
$_GET [通过GET方法传递给该脚本的变量]
$_POST [通过POST方法传递给该脚本的变量]
$_COOKIE [cookie变量数组]
$_FILES [与文件上载相关的数组]
$_REQUEST [所有用户输入的变量数组]
$_SESSION [会话变量数组]
常量:被定义后不能改变的量
常量没有$符
常量只可以保存布尔值,整数,浮点数或字符串数据
defin("TOTAL",100);
TOTAL一直就是100
4.访问表单变量
$_POST["username"];
$_GET["username"];

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
