Page 1 of 1

What do the 1, 0 and - 1 mean?

Posted: Thu Oct 27, 2011 5:23 am
by jujubuddy
Hi all,

Total noob here. I have been trawling through w3schools tutorials and finding most of it easy enough but I'm not sure what return values are doing in this function.

I was thinking true and false, but then the -1 totally threw me.

Thanks in advance!

Code: Select all

<?php
function myfunction($v1,$v2)
{
if ($v1===$v2)
  {
  return 0;
  }
if ($v1>$v2)
  {
  return 1;
  }
else
  {
  return -1;
  }
}
$a1=array(0=>"Dog",1=>"Cat",2=>"Horse");
$a2=array(3=>"Dog",1=>"Cat",5=>"Horse");
print_r(array_diff_uassoc($a1,$a2,"myfunction"));
?>

Re: What do the 1, 0 and - 1 mean?

Posted: Thu Oct 27, 2011 6:26 am
by social_experiment
In this function those values are returned depending on the value of the arguments passed to the function, they don't directly imply true or false.