How to clear empty array in php

coldplay.xixi
Release: 2023-03-03 20:14:01
Original
4277 people have browsed it

php method to clear empty arrays: use the [array_filter()] function in the php code to remove the empty array, the syntax is [array_filter($array,$callback,$flag)].

How to clear empty array in php

php method to clear empty arrays:

In php, you can use "array_filter()" to clear empty arrays Array removal. The function of this function is to use the callback function to filter the units in the array. Its function syntax is "array_filter($array,$callback,$flag)". When using it, you only need to pass the array into the first parameter.

Sample code:

<?php
$arr = array(
    0=>&#39;cyy&#39;,
    1=>false,
    2=>-1,
    3=>null,
    4=>&#39;&#39;
);
print_r(array_filter($arr));
Copy after login

Output result:

How to clear empty array in php

##Related learning recommendations:

php graphic tutorial

The above is the detailed content of How to clear empty array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!