find the cube root of a number in php

To find the cube root of a number in PHP, you can use the pow() function with a fractional exponent of 1/3.

Here's an example code snippet:

main.php
$num = 27;                 // the number whose cube root we want to find
$cube_root = pow($num, 1/3);  // calculate the cube root
echo "The cube root of $num is: $cube_root";   // Output the result
198 chars
4 lines

The output of this code will be:

main.php
The cube root of 27 is: 3
26 chars
2 lines

In this example, we used the pow() function with an exponent of 1/3 to calculate the cube root of 27.

Note that you can also use the sqrt() function to calculate the square root of a number in PHP.

related categories

gistlibby LogSnag