Home > Backend Development > PHP Tutorial > Constant_PHP Tutorial

Constant_PHP Tutorial

WBOY
Release: 2016-07-13 17:26:24
Original
854 people have browsed it

Any PHP scripting language is created using consecutive statements. A statement can be an assignment statement, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements often end with a semicolon (;). In addition, using volume support, a group of statements can be compressed so that statements can be grouped into statement groups. A statement group is a statement about itself. The different statement types are described in this chapter.
Constants
PHP defines some constants to provide structures to enable it to define more types at runtime. Constants and variables are very similar, but their syntax is slightly different.
The predefined constants are __FILE__ and __LINE__. When processing them, you will find that they match the file name and line number. Please refer to the following example:

Example 6-1. Using __FILE__ and __LINE__ //Use __FILE__ and __LINE__
function report_error($file, $line, $message) {
echo "An error occurred in $file on line $line: $message.";
}
report_error(__FILE__,__LINE__, "Something went wrong!");
?>
You can define other constants using the functions define() and undefine().
 
Example 6-2. Defining Constants // Defining constants
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
undefine ("CONSTANT");
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531957.htmlTechArticleAny PHP scripting language is created using consecutive statements. A statement can be an assignment statement, a function call, a loop, a conditional statement or even one that does nothing...
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