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 - PHP Tutorial
From the course: PHP for Web Designers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
How PHP makes decisions3m 30s
-
(Locked)
Changing output depending on the current time9m 1s
-
(Locked)
Adjusting the server's time zone8m 57s
-
(Locked)
Displaying an up-to-date copyright notice6m 18s
-
(Locked)
Challenge: Displaying an image of the month2m 15s
-
(Locked)
Solution: Displaying an image of the month5m 12s
-
(Locked)
Understanding what PHP treats as true and false2m 57s
-
(Locked)
-
-
-
-
-