Methods to determine if array elements are not spaces: 1. Use the "foreach ($arr as $value){}" statement to traverse the array; 2. Use the "if($value!=" ")" statement to determine Whether the array elements are spaces; 3. If all array elements are not empty, output "array elements are not spaces".
The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer
php determines that the array element cannot be a space
Idea:
Use the foreach statement to traverse the array, and assign the key value of the current array to $value## in each loop
$i
$i=0, and use
break; to exit the entire loop.
$i value is 0, then you can know whether there is a space element in the array
<?php header("Content-type:text/html;charset=utf-8"); $arr = array(10,"php中文网",20," ","php教程"); $i=0; foreach ($arr as $value) { if($value!=" "){ $i++; }else{ $i=0; break; } } if ($i==0) { echo("数组中有元素为空格"); } else { echo("数组元素都不为空格"); } ?>
## Recommended learning: "
PHP video tutorialThe above is the detailed content of How to determine if array elements are not spaces in php. For more information, please follow other related articles on the PHP Chinese website!