<?PHP echo sqrt(2); //1.4142135623731 echo sqrt(2.5); //1.5811388300842 echo sqrt(-2.5); //NAN echo sqrt("7429"); //NAN echo sqrt(3); //1.7320508075689 echo sqrt(4); //2 ?>
The following code can calculate the square root of a numeric array.
<?PHP $arr = array("2","3.4","5.342","0","3","54","6.3"); for ($ii=0;$ii<count($arr);$ii++) { $arr[$ii] = sqrt($arr[$ii]); } print_r($arr); ?> //the result is: Array ( [0] => 1.4142135623731 [1] => 1.8439088914586 [2] => 2.3112767034693 [3] => 0 [4] => 1.7320508075689 [5] => 7.3484692283495 [6] => 2.5099800796022 )