开发者

PHP how to count the arrays values?

开发者 https://www.devze.com 2022-12-13 16:48 出处:网络
I\'m trying to count all the values in the array and check if one value was ent开发者_JAVA技巧ered and if so display a certain message for it and if there was more then one value entered display a dif

I'm trying to count all the values in the array and check if one value was ent开发者_JAVA技巧ered and if so display a certain message for it and if there was more then one value entered display a different message for it.

How will I be able to this and where should I add it to my code?

Here is the code below.

if ($array == 1){
    echo $array . " has been entered";
} else {
    echo implode(", ", $array) . " have been entered";
}


if (count($array) == 1){
        echo $array[0] . " has been entered";
} else {
        echo implode(", ", $array) . " have been entered";
}


if (count($array)){
    echo implode(", ", $array) . " have been entered";
}


count($array) gives you number of elements in the array

0

精彩评论

暂无评论...
验证码 换一张
取 消