Home > Backend Development > PHP Problem > What is the method to determine if an array is not empty in php

What is the method to determine if an array is not empty in php

hzc
Release: 2023-03-01 22:28:02
Original
3567 people have browsed it

The method to determine if the array is not empty in php is: 1. Use the [empty($array_test)] function. If the array [$array_test] is empty, the function returns true; 2. Use [if($array_test) )] Judgment condition, if the array is empty, the if judgment condition returns false.

What is the method to determine if an array is not empty in php

The array is empty. It means that the array does not contain any elements.

There are many ways to judge that the array is empty: the following one List them out

empty($array_test) //If the array $array_test is empty, then this function returns true

if($array_test) //If the array is empty, then the conditional judgment of if Is false

count($array_test) //Calculate the number of array elements. If it is 0, it is empty

sizeof($array_test) //The alias usage of count() is the same as the return

//In fact, there are some ways to judge whether the array is empty. The commonly used ones are these

Additional note

If the array is not defined

It can also be used

isset($array_test)//Judge whether the array is defined

Recommended tutorial: "php tutorial"

The above is the detailed content of What is the method to determine if an array is not empty in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template