Get the App
SLTechnology News&Howtos  ›  Development  › 

PHP function array_filter how to filter elements in an array with a callback function

Shulou Source: shulou.com Published: 2022-06-01 02:56:07 09月22日 Update

Editor to share with you the PHP function array_filter how to use the callback function to filter the elements in the array, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Array_filter uses callback functions to filter elements in the array.

Function test_odd ($var) {return ($var & 1);} $a1=array ("a", "b", 2jin3jade 4); print_r (array_filter ($A1, "test_odd"))

Output:

Array

(

[2] = > 2

[3] = > 3

[4] = > 4

)

This is all the content of the article "how the PHP function array_filter uses callback functions to filter elements in the array". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions elements arrays articles content not much most more knowledge industry information information channels channels references learning help output Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Shulou Technology MariaDB NVidia