<?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
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
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); *
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
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
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)) {
13 Jul 2016
PHP-ExcelReader: PHP class library for parsing excel files. PHP-ExcelReader: PHP class library for parsing excel files. PHP-ExcelReader is an open source project based on PHP. Its function is to parse excel files. The official website of PHP-ExcelReader is as follows:
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
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images