How can the pow() function be used as an alternative to eval() for performing exponentiation in PHP calculations?

Using the pow() function in PHP is a safer alternative to using eval() for performing exponentiation in calculations. Eval() can execute any arbitrary code passed to it, which poses a security risk. By using pow(), you can specifically perform exponentiation without the risk of executing unintended code.

// Using pow() function for exponentiation
$base = 2;
$exponent = 3;
$result = pow($base, $exponent);

echo $result; // Output: 8