View Single Post
  #6 (permalink)  
Old 08-08-2007, 05:06 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Admin
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 440
iTrader: (0)
TeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to beholdTeraTask is a splendid one to behold
It just depends on the type of information that you're trying to compare and how you want to compare it.

PHP Code:
//Let's say we have this function
//NOTE: All functions do what they say they'll do, even if not defined.
function number_of_members_attending($meeting_id) {
  if (
meeting_exists($meeting_id)) {
    
//Now, calculate the number of members and store in $number_of_members

    
return $number_of_members;
  } else {
    
//Meeting doesn't exist, so this question is inappropriate
    
return false;
  }

Now, this function will return 3 possible values of interest:

1) false if the meeting_id is invalid or no meeting exists;
2) 0 if the meeting has no registered users;
3) > 0 if the meeting has some number of members.

Now, let's say that you were writing code which uses the function above:

PHP Code:
$members_attending number_of_members_attending(20070315);
if (
$members_attending) {
  echo 
"There are ".$members_attending." members attending your meeting.";
} else {
  echo 
"No meeting is scheduled.";

The code above would be inaccurate as a meeting may be scheduled and no members set to attend yet, so you could be more explicit by using:

PHP Code:
$members_attending number_of_members_attending(20070315);
if (
$members_attending === false) {
  echo 
"No meeting is scheduled.";
} elseif (
$members_attending == false) {  //I'm just doing that as an example, normally I'd use $members_attending == 0
  
echo "No one is scheduled to attend this meeting yet.";
} else {
  echo 
"There are ".$members_attending." members attending your meeting.";  

By using identically equal ( === ) I am able to specifically distinguish between false and 0 which matters in this case (and, also, in the strpos case).

I hope that helps!

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to TeraTask For This Useful Post:
Lee (08-08-2007)