Home php教程 php手册 php笔记之:数据类型与常量的使用分析

php笔记之:数据类型与常量的使用分析

Jun 13, 2016 am 11:52 AM
php and use analyze variable constant data of notes type set up

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] )

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles