Home PHP Libraries Other libraries PHP class library for manipulating arrays
PHP class library for manipulating arrays
<?php
class ArrayHelper{
    
    static function removeEmpty(& $arr, $trim = TRUE)
    {
        foreach ($arr as $key => $value)
        {
            if (is_array($value))
            {
                self::removeEmpty($arr[$key]);
            }
            else
            {
                $value = trim($value);
                if ($value == '')
                {
                    unset($arr[$key]);
                }
                elseif ($trim)
                {
                    $arr[$key] = $value;
                }
            }
        }
    }

Remove blank elements from the array (including elements with only blank characters)

Usage:

@code php

$arr = array('', 'test', ' ');

ArrayHelper::removeEmpty($arr);

dump($arr);

There will be only 'test' in the output result

@endcode

@param array $arr The array to be processed

@param boolean $trim Whether to call the trim function on the array elements



Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

xinputemulator PHP class for manipulating XML as a database xinputemulator PHP class for manipulating XML as a database

29 Jul 2016

xinputemulator:xinputemulator PHP operates XML as a database class: xml.class.php file code Copy the code as follows: <?php * example Read data: * * $xml = new xml("dbase.xml",'table') ; * * $data=$xml->xml_fetch_array(); * * echo "<pre style="font-size:12px;">"; * * print_r($data); *

php Http_Template_IT class library for template replacement_PHP tutorial php Http_Template_IT class library for template replacement_PHP tutorial

21 Jul 2016

php Http_Template_IT class library for template replacement. Two simple templates: Copy code The code is as follows: html head title{title}/title /head body font color=red size=6center{title}/center/font hr pre{body}/pre /body /html Copy code Code

php auth_http class library for identity verification_PHP tutorial php auth_http class library for identity verification_PHP tutorial

21 Jul 2016

php auth_http class library for identity verification. Copy the code as follows: ?php require_once("Auth/HTTP.php"); //Set the database connection options $auth_options=array( 'dsn'="mysql://root:1981427@localhost/test", // Database connection word

PHP db class library for database operations_PHP tutorial PHP db class library for database operations_PHP tutorial

21 Jul 2016

PHP db class library performs database operations. Copy the code as follows: ?php require_once "DB.php"; //Contains class library files $conn = DB::connect("mysql://root:1981427@localhost/test"); //Connect to the database if (! DB::isError($conn)) {

PHP implements class library usage for exporting excel data PHP implements class library usage for exporting excel data

01 Jun 2018

This article mainly introduces the usage of the class library for exporting excel data in PHP, and analyzes the related implementation skills of reading and exporting Excel data in PHP in the form of examples. Friends in need can refer to the following

PHP class library for generating QR codes (QRCode method) PHP class library for generating QR codes (QRCode method)

25 Jul 2016

PHP class library for generating QR codes (QRCode method)

See all articles