Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Php determines which functions the array is not empty.

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report