php笔记之:数据类型与常量的使用分析_PHP
setType — 设置变量的类型
bool settype ( mixed $var , string $type )
将变量 var 的类型设置成 type 。
type 的可能值为:
•“boolean” (或为“bool”,从 PHP 4.2.0 起)
•“integer” (或为“int”,从 PHP 4.2.0 起)
•“float” (只在 PHP 4.2.0 之后可以使用,对于旧版本中使用的“double”现已停用)
•“string”
•“array”
•“object”
•“null” (从 PHP 4.2.0 起)
如果成功则返回 TRUE,失败则返回 FALSE。
intval(), floatval(), stringval() 不会改变原变量的类型。
isset— 检测变量是否设置
bool isset ( mixed $var [, mixed $var [, $... ]] )
如果 var 存在则返回 TRUE,否则返回 FALSE。
如果已经使用 unset() 释放了一个变量之后,它将不再是 isset()。若使用 isset() 测试一个被设置成 NULL 的变量,将返回 FALSE。同时要注意的是一个 NULL 字节("\0")并不等同于 PHP 的 NULL 常数。
Note: 警告 isset() 只能用于变量,因为传递任何其它参数都将造成解析错误。若想检测常量是否已设置,可使用 defined() 函数。
empty — 检查一个变量是否为空
bool empty ( mixed $var )
如果 var 是非空或非零的值,则 empty() 返回 FALSE。换句话说,""、0、"0"、NULL、FALSE、array()、var $var; 以及没有任何属性的对象都将被认为是空的,如果 var 为空,则返回 TRUE,当变量没有置值时不产生警告。
unset — 释放给定的变量
void unset ( mixed $var [, mixed $var [, $... ]] )
unset() 销毁指定的变量。注意在 PHP 3 中,unset() 将返回 TRUE(实际上是整型值 1),而在 PHP 4 中,unset() 不再是一个真正的函数:它现在是一个语句。这样就没有了返回值,试图获取 unset() 的返回值将导致解析错误。
gettype — 获取变量的类型
string gettype ( mixed $var )
返回 PHP 变量的类型 var .
变量类型测试函数
is_bool()
is_int()
is_integer()
is_long()
is_string()
is_float()
is_double()
is_real()
is_array()
is_object()
is_resource()
is_null()
is_scalar()
is_numberic()
is_callable()
查阅手册注意事项
1. 常规函数
bool copy ( string source, string dest )
2. 带有mixed , mixed表示可以传任何类型的数据
bool chown ( string filename, mixed user )
3. 带有&参数的函数, 表示引用赋值, 这个参数不能传值,只能传一个变量,然后函数将变量的值改变,我们在使用这个变量时,值也是变化的
bool arsort ( array &array [, int sort_flags] )
4.默认函数 带有[]的函数, 表示这个参数是可选的,如果你传值了就使用你传的值,如果没有传值则使用默认值
直接在声明函数时,就为参数给初值。
可选值和必须值, 必须从后向前设置
bool arsort ( array &array [, int sort_flags] )
5. 带有...的参数函数, ...表示可以传任意多个参数
int array_unshift ( array &array, mixed var [, mixed ...] )
6. 回调函数 带有callback, 就是调用这个函数时需要我们传一个函数进来(函数名,函数名字串)
array array_filter ( array input [, callback callback] )

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

AI Hentai Generator
Generate AI Hentai for free.

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
