**Heads up!** To view this whole video, sign in with your Courses account or enroll in your free 7-day trial.
Sign In
Enroll

Start a free Courses trial

to watch this video

PHP7 also brings us some new operators. The first one we’re going to explore is the spaceship operator. With a name like that, who doesn’t want to use it? The Null Coalesce Operator, is effectively the fabled if-set-or. It will return the left operand if it is not NULL, otherwise it will return the right.

Example | Name | Result |
---|---|---|

$a == $b | Equal |
if `TRUE` is equal to $a after type juggling.$b |

$a === $b | Identical |
if `TRUE` is equal to $a, and they are of the same
type.
$b |

$a != $b | Not equal |
if `TRUE` is not equal to $a after type juggling.$b |

$a <> $b | Not equal |
if `TRUE` is not equal to $a after type juggling.$b |

$a !== $b | Not identical |
if `TRUE` is not equal to $a, or they are not of the same
type.
$b |

$a < $b | Less than |
if `TRUE` is strictly less than $a.$b |

$a > $b | Greater than |
if `TRUE` is strictly greater than $a.$b |

$a <= $b | Less than or equal to |
if `TRUE` is less than or equal to $a.$b |

$a >= $b | Greater than or equal to |
if `TRUE` is greater than or equal to $a.$b |

$a <=> $b | Spaceship |
An integer less than, equal to, or greater than zero when
is respectively less than, equal to, or greater
than $a. Available as of PHP 7.
$b |

$a ?? $b ?? $c | Null coalescing |
The first operand from left to right that exists and is not .
`NULL` if no values are defined and not `NULL` . Available as of PHP 7.
`NULL` |

#### Documentation

Comparison Operators

Spaceship Operator RFC

Null Coalesce Operator RFC

**Related Discussions**

Have questions about this video? Start a discussion with the community and Treehouse staff.

Sign up**Related Discussions**

Have questions about this video? Start a discussion with the community and Treehouse staff.

Sign up

You need to sign up for Treehouse in order to download course files.

Sign upYou need to sign up for Treehouse in order to set up Workspace

Sign up