PHP 5 constants

WBOY
Release: 2016-07-29 08:58:20
Original
934 people have browsed it

  • PHP Constants

A constant is an identifier for a simple value. This value cannot be changed in the script.
A constant consists of English letters, underscores, and numbers, but numbers cannot appear as the first letter. (The $ modifier is not required on the constant name).
Note: Constants can be used throughout the script.

  • Set PHP constants

To set constants, use the define() function. The function syntax is as follows:

<code><span><span>define</span></span>(<span>string</span> constant_name, mixed value, case_sensitive <span>=</span><span>true</span>)</code>
Copy after login

This function has three parameters:
constant_name: required parameter, constant name, i.e. identifier.
value: required parameter, value of constant.
case_sensitive: optional parameter, specifies whether to be case sensitive, set to true to indicate insensitivity.

  • Constants are global

After a constant is defined, it defaults to a global variable and can be used anywhere in the entire running script.
The following example demonstrates the use of constants within a function. Even if the constant is defined outside the function, the constant can be used normally.

<code><span><?php</span>
define(<span>"GREETING"</span>, <span>"欢迎访问 Runoob.com"</span>);
<span><span>function</span><span>myTest</span><span>()</span> {</span><span>echo</span> GREETING;
}
 myTest();    <span>// 输出 "欢迎访问 Runoob.com"</span><span>?></span></code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced PHP 5 constants, including related content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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!