From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding what PHP treats as true and false

Understanding what PHP treats as true and false - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Understanding what PHP treats as true and false

It might seem odd to pose a philosophical question about the nature of truth in a video about PHP. After all, there's no ambiguity about the comparisons we've used in if else conditions so far. One value is either equal to another or greater than it. Or it isn't. What's true and false is clear cut. But in common with other programming languages, PHP supports the concept of values that are implicitly true or false. Sometimes, these are called truthy and falsey values. JavaScript shares the same concept, but PHP's definition of true and false is slightly different. Let's start with what PHP regards as false. The keywords, false and null. These are keywords so they should never be wrapped in quotes. If you use quotes, they're regarded as ordinary strings. Both false and null are case insensitive. Zero, either as a number or as a string, in other words, the number zero between quotes but not spelled out as a word. An empty string. That's a pair of quotes with nothing between them, not…

Contents