Syntax

PHP Null Coalescing Syntax

In PHP, null coalescing: uses a default if a value is null or unset — $page = $_GET['page'] ?? 1;

Quick Answer

Syntax
$page = $_GET['page'] ?? 1;
PHPSyntax

Null Coalescing

Code example
$page = $_GET['page'] ?? 1;

Uses a default if a value is null or unset.

Learn More

How to null coalescing in PHP

  1. Open your PHP file or editor.
  2. Copy the example, then replace its sample names and values for your code.

PHP Null Coalescing Syntax

Use $page = $_GET['page'] ?? 1;.

Related Syntax References

Frequently asked questions

What is the PHP syntax for null coalescing?

Use this pattern: $page = $_GET['page'] ?? 1;

Can I copy this PHP code example?

Yes. Use Copy code and adapt the example to your program.

Is this PHP syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify