Category Archives: PHP

PHP 7.4 – Null Coalesce Assignment Operator

PHP 7.4 added a new Null Coalesce Assignment Operator (??=) which is an enhancement of Null Coalesce Operator (??) introduced in PHP 7. The Null Coalesce Assignment Operator (??=) assigns the value of the right-hand parameter if the left-hand parameter is null. If the left-hand parameter is not null then its value is not changed. The Null Coalesce Assignment Operator is sometimes also called as Null Coalesce Equal Operator.
Read more »

PHP 7 – Combined Comparison (Spaceship) Operator

In this post we will take a look and another new operator in PHP 7. This operator is the Combined Comparison or Spaceship operator (<=>). This operator is a three way comparison operator. It will do greater-than, less-than and equal comparisons between two operands.

The spaceship operator (<=>) returns -1 if the left side is smaller, 0 if the values are equal and 1 if the left side is larger. It can be used on all generic PHP values with the same semantics as < , <=, ==, >=, >. This operator is similar in behavior to strcmp() or version_compare(). This operator can be used with integers, floats, strings, arrays, objects, etc.
Read more »

PHP 7 – Null Coalesce Operator

PHP 7 brings a lot of improvements, features and new operators as compared to the earlier versions on PHP. One of the new operators is the Null Coalesce Operator (??). This operator can be used instead of using isset() along with the ternary operator (?:).

The Null coalesce operator (??) returns the result of its first operand if it exists and is not NULL, or else it will return its second operand. Using this operator like $_GET[‘mykey’] ?? “” will not raise an E_NOTICE, and can be safely used.
Read more »

How to create a zip file using PHP

Recently I had to write a script to create a zip file containing different files and folders. PHP has a ZipArchive class which can be used easily to create zip files. In this article we will see how to create zip files in PHP. We will create different zip files from different files and folders.

Read more »

How to create CSV file using PHP

CSV (comma-separated values) is one of the most popular methods for transferring tabular data between applications. Lot of applications want to export data in a CSV file. In this article we will see how we can create CSV file using PHP. We will also see how to automatically download the file instead of just showing it in the browser or giving the user a link to download it.
Read more »