PHP Online Compiler
Example: How to Find Area of a Circle with Diameter in PHP using Functions
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php // To calculate the diameter function diameter($r) { return 2 * $r; } // To calculate the circumference function circumference($r) { return 2 * 3.14 * $r; } // To calculate the area function area($r) { return 3.14 * ($r * $r); } $r = 12; // $r = radius echo "\nDiameter = " . diameter($r) . " units"; echo "\nCircumference = " . circumference($r) . " units"; echo "\nArea = " . area($r) . " sq. units"; ?>
Output
Clear
ADVERTISEMENTS