如何确定一个数组是否有任何元素? [英] How to determine if an array has any elements or not?
本文介绍了如何确定一个数组是否有任何元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查找数组中是否包含一个或多个元素?
How do I find if an array has one or more elements?
我需要执行一个代码块,其中数组的大小大于零.
I need to execute a block of code where the size of the array is greater than zero.
if ($result > 0) {
// Here is the code body which I want to execute
}
else {
// Here is some other code
}
推荐答案
您可以使用count()
或sizeof()
PHP函数:
You can use the count()
or sizeof()
PHP functions:
if (sizeof($result) > 0) {
echo "array size is greater than zero";
}
else {
echo "array size is zero";
}
或者您可以使用:
if (count($result) > 0) {
echo "array size is greater than zero";
}
else {
echo "array size is zero";
}
这篇关于如何确定一个数组是否有任何元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文