Method: 1. Use the foreach statement to loop through the array, the syntax is "foreach ($array as $value){}"; 2. In the loop body, determine whether the "$value" value is greater than 0, and if it is greater Then output, the syntax is "if($value>0){echo $value;}".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php array query greater than 0 element method
Implementation idea:
Loop through the array
Judge whether the array elements are greater than 0 one by one
Implementation method:
Use The foreach statement loops through the array
In the loop body, determine whether the array element is greater than 0. If it is greater than 0, just output the element.
Implementation example:
<?php header('content-type:text/html;charset=utf-8'); $array = array(1,0,-1,3,-3,4,5,6,7,-2); foreach ($array as $value){ if($value>0){ echo $value."<br>"; } } ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to query elements greater than 0 in a php array. For more information, please follow other related articles on the PHP Chinese website!