• Post category:PHP

How to Create Empty Array PHP

Create Empty Array PHP

Learn how to create empty array php with example codes. When the situation comes to store user input in an array, we need to create an empty array.

Three types of creating empty array:

// Method 1:
$emptyArray1 = [];
// Method 2:
$emptyArray2 = array();
// Method 3:
$emptyArray3 = (array) null;

Here, we have an empty array of three types. The most used method 1. If we add value to the array, you need to use the array_push() method like:

array_push($emptyArray1, "Wonder", "Develop");

To print the array, we need to use print_r() method. If the array is empty it returns “array()



empty array in php

Leave a Reply