PHP Tips

True and False values

In PHP, there are some rules for a boolean evaluation:

  • for numeric values:
    • 0 is false
    • anything else is true
  • for string values:
    • the empty string is false
    • "0" is evaluated to false
    • all else is true
  • for an array
    • an empty array is false
    • an array with any elements is true
  • for an object
    • an empty object (no defined methods or functions) is false
    • true otherwise

PHP provides 2 built-in constants:

  • TRUE defined as the integer value 1
  • FALSE defined as the empty string

Assignment, Equality and Identity

PHP defines 3 operations with its own operator:

  • "=" assign a value to a variable
  • "==" compares the values of 2 operands.
  • "===" compares their values and their types

"==" and "===" do not work on arrays or objects.

Get in touch!

We'd love to hear from you, what you think about this page or what we can do for you.

Contact Us

View this page with IE8+, Mozilla Firefox, Safari, Chrome and Mobiles

Last modificaton on 21 May 2015 by St├ęphane Van Nerom

© 2006-2014 - GVN - All rights reserved