I understand there are fairly robust math packages for PHP, but what I'm trying to do isn't that complex. I'm looking to calculate the Cube Root of a number. Solving for x in (x^3 = 100
) would normally require echo 100^(1/3)
. Running this code in PHP returns neither an error or a correct number.
The ^
character is XOR
in PHP, a bitwise operator.
To perform power-operations (exponents), you should look into the PHP-defined pow()
method. To use this with your sample code, it would be:
echo pow(100, 1/3);
Starting in PHP 5.6, they introduced an exponentiation operator too, **
:
echo 100 ** (1/3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With