" to determine whether the array length is greater than 1, the syntax is "$len>1" , if the length is greater than 1, there are multiple values in the array, otherwise there is 1 value or no value in the array."/> " to determine whether the array length is greater than 1, the syntax is "$len>1" , if the length is greater than 1, there are multiple values in the array, otherwise there is 1 value or no value in the array.">
Home >Backend Development >PHP Problem >How to determine if there are multiple values in an array in php
Judgment method: 1. Use the count() function to obtain the array length, with the syntax "$len=count($arr);"; 2. Use the comparison operator ">" to determine whether the array length is greater than 1. Syntax "$len>1", if the length is greater than 1, there are multiple values in the array, otherwise there is 1 value or no value in the array.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer
php judgment array Is there a method for multiple values
1. Use the count() function to obtain the length of the array
The count() function can count the length of the array The number of all elements
<?php header('content-type:text/html;charset=utf-8'); $arr=array(1=>"1","a"=>"red","ab"=>"2","b12"=>"green",3=>"3"); var_dump($arr); $len=count($arr); echo "数组长度为:".$len; ?>
2. Determine whether the array length is greater than 1
The array length is the number of array elements:
If the array length is greater than 1, there are multiple values in the array
If the array length is less than or equal to 1, there is 1 value in the array Or no value (empty array)
if($len>1){ echo "数组中有多个值"; }else{ echo "数组中有1个值或没有值"; }
Let’s modify it and delete all the values of the $arr array
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine if there are multiple values in an array in php. For more information, please follow other related articles on the PHP Chinese website!