Constants are identifiers which are used to store values that cannot be changed once initialized.
A constant doesn’t begin with a dollar ($) sign. The convention for constants is, the name of a constant should always be written in uppercase.
We use the function define to create constants. Below example demonstrates creating and using constants in PHP:
<?php
define("PI", 3.142);
print(PI);
$area = PI*10*10; //Let radius be 10
print("<br />Area of circle is: $area");
?>
A video tutorial on declaring and using constants in PHP:
Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.
He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.
He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.
Leave a Reply