I keep getting the following error and I was wondering on how to fix?
This is the second time I got this error I fixed it the first time but for some reason I cant fix it the second time.
Fatal error: Unsupported operand types on line 14
Here is line 14
$sub=$a-$b;
Here is the full code below.
<?php
$x=array(2,10);
$y=array(3,5);
$z=D($x,$y);
echo ('sum is :'.$z);
/** compute Euclidean distance http://en.wikipedia.org/wiki/Euclidean_distance */
function D ($a, $b)
{
$sub=$a-$b;
return pow($sub,2);
}
function distance_betwen($p,$q)
{
$nu_argu=func_num_args();
if( $nu_argu!=2)
{
echo 'please enter a valid 2 coordinates like this (1,2)';
}
else if (sizeof($p)!=sizeof($q))
{
echo 'values of each pair must have the same dimention';
}
else
{
$c=array_map("D",$p,$q);
return pow(array_sum($c),0.5);
}
}
?>
Your
$z=D($x,$y);$x and $y is arrayYou can’t do substraction with two
array$sub=$a-$b;