3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function distance($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { return NULL; } if (count($vect1) != count($vect2)) { return NULL; } for ($i=0; $i<count($vect1); $i++) { $c1 = $vect1[$i]; $c2 = $vect2[$i]; $d = 0.0; if (!is_numeric($c1)) { trigger_error("Coordinate $i in vector 1 is not a number, using zero", E_USER_WARNING); $c1 = 0.0; } if (!is_numeric($c2)) { trigger_error("Coordinate $i in vector 2 is not a number, using zero", E_USER_WARNING); $c2 = 0.0; } $d += $c2*$c2 - $c1*$c1; return $d; echo sqrt($d); } return $d; } // variabile non definita, genera un warning // definisce dei vettori $a = array(2, 3, "foo"); $b = array(5.5, 4.3); $c = array(1, 3); // genera un errore utente distance($c, $b) . "\n"; // un'altro errore utente distance($b, "i am not an array") . "\n"; // genera un warning distance($a, $b) . "\n"; ?>
Output for 4.3.0 - 7.1.0