80);}"; 2. Use array_filter() to call the custom function Process the specified array, "array_filter($arr,"f")"."/> 80);}"; 2. Use array_filter() to call the custom function Process the specified array, "array_filter($arr,"f")".">

Home  >  Article  >  Backend Development  >  How to find a number greater than 80 in a php array

How to find a number greater than 80 in a php array

青灯夜游
青灯夜游Original
2022-05-26 19:58:481668browse

Method: 1. Customize a function to process arrays and return numbers greater than 80. The syntax is "function f($n){return($n>80);}"; 2. Use array_filter ()Call a custom function to process the specified array, "array_filter($arr,"f")".

How to find a number greater than 80 in a php array

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use array_filter () function filters the array to obtain numbers greater than 80.

array_filter() function uses a callback function to filter elements in the array.

This function passes each key value in the input array to the callback function. If the callback function returns true, the current key value in the input array is returned to the result array. Array key names remain unchanged.

Implementation method: Just set the conditions in the callback function called by the array_filter() function and return array elements greater than 80.

<?php
function f($num){
	 return($num>80);
}
$arr=array(8,81,80,89,90,23,99,100);
var_dump($arr);
$res=array_filter($arr,"f");
var_dump($res);
?>

How to find a number greater than 80 in a php array

Filter numbers less than or equal to 80 and only return numbers greater than 80.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to find a number greater than 80 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