The difference between php variables and constants

(*-*)浩
Release: 2023-02-26 06:42:01
Original
2453 people have browsed it

The difference between php variables and constants

Constant:

Identifier used to store a data that will not change and is not expected to change (the naming rules are the same as variables)

Definition form: (Recommended learning: PHP video tutorial)

Use define() function definition

Use form: define ("Constant name", constant value)

The difference between php variables and constants

Use counst syntax definition

Usage form: counst constant name = constant value

Use constants: There are two forms 1. Use the name directly 2. Use the constant() function: constant ("constant name")

The difference between php variables and constants

Use constants: There are two forms 1. Use the name directly 2. Use the constant () function: constant ("constant name")

The difference between constants and variables:

Definition form Different (php variables have no defined keywords or functions and are defined when assigning values. PHP constants must be defined using the define() function);

The usage form is different (constants do not require the $ symbol);

Different degrees of variability (the value of a constant cannot be changed or destroyed);

Different scopes (constants have super-global scope (can be used directly inside and outside the function));

The available types are different (constants can only store scalar types: int, float, string, bool);

The above is the detailed content of The difference between php variables and constants. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!