How to create an empty array in PHP? Explain with example?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

array() function is use to create an array in our PHP and php supports three types of array-

  • index array= it has index values
  • associative array= it has string keys
  • multidimensional array= it contains one or more array in particular array

 Why it is always good practice to declare an empty array and then push the items to that array?

when declare an empty array and then start entering elements in it later. with the help of this, it can prevent different errors due to a faulty array. it helps to have the information of using bugged, rather having the array. it saves time during the debugging. Most of the time it may not have anything to add to the array at the point of creation.

Syntax
$emptyArray = [];
      or
$emptyArray = array();

       or
$emptyArray = (array) null;
EMPTY ARRAY
example
<?php

		$subjects = array();
		if (count($subjects) == 0)
		{
				echo " the array is empty";
		}
		else
		{
		    echo "array is not empty";
		}
		
?>

output

the array is empty

Related Posts

PR Points Calculator : The Ultimate Guide to Immigration Eligibility Around the World

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

The Complete Guide to Certified FinOps Professional: Career Path, ROI, and Technical Mastery

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Certified FinOps Manager: The Complete Guide to Mastering Cloud Value and Career Growth

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Certified FinOps Engineer Career Path for Engineers and Managers

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Certified FinOps Architect: Strategic Cloud Optimization and Financial Governance

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Mastering Data Pipelines: The Complete Career Guide to CDOM – Certified DataOps Manager

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x