What do the 1, 0 and - 1 mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jujubuddy
Forum Newbie
Posts: 2
Joined: Mon Jul 11, 2011 5:03 pm

What do the 1, 0 and - 1 mean?

Post 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"));
?>
Last edited by Benjamin on Thu Oct 27, 2011 7:05 am, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply