My Blog

contains PHP and other web related content. (Sometimes there are some off topic things - don't freak out!)

PHP – Return results of comparison

A useful reminder: you can make use of returning the results of comparisons for is*() functions. Let me explain that further…

PHP allows you to get the result of a comparison in a variable. Any variable you can return from a function. My my amazing transitive skills, I say you can return the comparison of a variable. Enough of this drivel – here’s an example:

1
2
3
4
5
6
7
8
function isGreaterThanFour($testVar)
{
  return $testVar > 4;
}
 
if (isGreaterThanFour(5)) {
  print 'yay!';
}

So – this is a very simple example, obviously – but it illustrates the powerful point of this functionality clearly.

Tags:

Leave a Reply

  • twitter loader

Follow me on twitter: @aaronsaray

The views on this website are my own and do not reflect the opinions of my employer or clients.
Creative Commons License Home | Open Source | Book | Music | Art | Bio | Resume | Contact
My Baby