Steps: 1. Customize a function to process arrays and return elements that fail. The syntax is "function f($n){return($n
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
In an array, store some representative results How to find the number of failing grades in the array?
In PHP, you can use the array_filter() function and count() function to find the number of failed elements in the array.
Implementation steps:
Step 1: Customize a function and set specified conditions to process the array
The score is greater than or equal to 60 is a passing grade, and anything less than 60 is a failing grade. Therefore, the condition of the custom function is less than 60:
function f($num){ return($num<60); }
Step 2: Use array_filter() to call the custom function to process the specified array and return the elements that failed the grade
The array_filter() function uses a callback function to filter elements in an 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.
$res=array_filter($arr,"f");
array_filter() function returns the filtered array.
Step 3: Use the count() function to count the number of elements in the filtered array
$len=count($res)
The number of elements in the filtered array means a failing grade (less than 60) The number of elements.
Complete sample code:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to find the number of failing grades in an array in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
