PHP Constants
2229 단어 trainingPHPConstantsChandigarh
PHP Constants
In this post, you will learn how to use constants to store static values in PHP.
What is Constant in PHP
A constant is a name or an identifier for a fixed worth. Constants are like variables, actually, once they are defined, they can not be undefined or changed (with the except magic constants).
Constants are very valuable for storing data that doesn't change while the script is running. Common examples of such data include configuration settings for example database username and password, site's base URL, company name, etc.
Constants are defined utilizing PHP's define() function, which accepts two arguments: the name of the constant, and its value. When characterized the constant value can be accessed at any time just by referring to its name. Here is a simple example: Read also: ASP.NET VS PHP
Example
//Defining constant
define("SITE_URL", "http://cbitss.in/php-training-in-chandigarh/ ");
//Using constant
echo 'For more detail about PHP -'. SITE_URL;
?>
The output of the above code will be:
For more detail about PHP - http://cbitss.in/php-training-in-chandigarh/
PHP Echo Statement is often used to display or output data in web browsers.
Tip: By storing the value in a constant rather than a variable, you can ensure that the value won't get changed accidentally when your application runs.
Naming Conventions for PHP Constants
The name of the constant must follow the same guidelines. The variable name, which means a valid continuous name should start with a letter or underscore, followed by any number of letters, numbers or underscores with an exception: the $ prefix isn't required for constant names.
Reference
이 문제에 관하여(PHP Constants), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/cbitssexp/items/93fdd5f96f79b4b9026d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(PHP Constants), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/cbitssexp/items/93fdd5f96f79b4b9026d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)