0){echo $value;}"."/> 0){echo $value;}".">

Home >Backend Development >PHP Problem >How to query elements greater than 0 in a php array

How to query elements greater than 0 in a php array

青灯夜游
青灯夜游Original
2022-05-07 16:11:552722browse

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;}".

How to query elements greater than 0 in a php array

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(&#39;content-type:text/html;charset=utf-8&#39;);   
$array = array(1,0,-1,3,-3,4,5,6,7,-2);
foreach ($array as $value){
    if($value>0){
    	echo $value."<br>";
	}
}
?>

How to query elements greater than 0 in a php array

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn