find the surface area of a cube in php

To find the surface area of a cube in PHP, you need to have the length of one of its edges. You can use that to calculate the surface area through the following formula:

surface area = 6 * edge^2

Here's a PHP function that takes the length of the edge as a parameter and returns the surface area of the cube:

main.php
function cubeSurfaceArea($edgeLength) {
  $surfaceArea = 6 * pow($edgeLength, 2);
  return $surfaceArea;
}
107 chars
5 lines

You can call this function with the length of the edge as an argument to get the surface area of the cube:

main.php
$cubeEdgeLength = 5;
$cubeSurfaceArea = cubeSurfaceArea($cubeEdgeLength);
echo "Surface area of the cube with edge length $cubeEdgeLength is: $cubeSurfaceArea";
161 chars
4 lines

This will output:

Surface area of the cube with edge length 5 is: 150
52 chars
2 lines

gistlibby LogSnag