The source code to create a constant using the define() function is given below. The given program is compiled and executed successfully.
<?php
//PHP program to create a constant
//using define() function.
define(PI, 3.14);
$radius = 5;
$area = PI * $radius * $radius;
print ("Area of circle: " . $area);
?>
Output:
Area of circle: 78.5
Explanation:
In the above program, we created a constant PI using the define() function that contains value 3.14. Then we created a local variable $radius initialized with 5. Then calculate the area of the circle and print the result on the console screen.
Program/Source Code:
The source code to create a constant using the define() function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a constant PI using the define() function that contains value 3.14. Then we created a local variable $radius initialized with 5. Then calculate the area of the circle and print the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer