Get the App
SLTechnology News&Howtos  ›  Development  › 

Php determines which functions the array is not empty.

Shulou Source: shulou.com Published: 2022-06-01 04:26:04 09月19日 Update

Editor to share with you php to determine which functions the array is not empty, I hope you will gain something after reading this article, let's discuss it together!

Php determines that the array is not empty: 1, empty () function, syntax "empty ($arr)", if the return value is false, then the array is not empty; 2, count () function, syntax "count ($arr)", if the return value is greater than or equal to 1, then the array is not empty.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php determines the function that the array is not empty

1. Empty () function

Use the function "empty ()" function to determine that the array is passed into this function. If true, it means empty; if it is false, it means it is not empty.

$arr = []; if (empty ($arr)) {/ / empty} else {/ / not empty}

2. Count () function

Get the number of items in the array through the "count ()" function, and then judge whether it is less than 1 according to the number of entries. If it is less than 1, it means it is empty.

$arr = []; if (count ($arr) < 1) {/ / empty} else {/ / not empty}

Expand knowledge:

Use implode () to output the array as a string to determine whether the output string is empty. At first glance, it seems to be a good method, but just like the previous one, it doesn't work for more than two-dimensional arrays. For example:

$arr= array (array (), array (), arr (www.yisu.com) ay ()); $str = implode (',', $arr); if (empty ($str)) echo "empty"; else echo "not empty"

It's obvious that $arr is a two-dimensional array with three empty arrays, which should be empty, but the output is non-empty. Failed to judge.

After reading this article, I believe you have a certain understanding of "what are the functions that php determines that the array is not empty". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Functions arrays representatives output knowledge articles grammar two-dimensional no not bad obvious three examples characters strings done tutorials methods right and wrong more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei MariaDB Linux vpn