How to trim recursively in PHP
Join the DZone community and get the full member experience.
Join For FreeI have started filling the content of one of my sites usage.cc.
So here is how how to trim recursively in PHP:
So here is how how to trim recursively in PHP:
<?php // Usage: echo Our_Util_String::trim('test'); /** * Util string functions. * * @author Svetoslav Marinov <svetoslavm@gmail.com> * @copyright Svetoslav Marinov <svetoslavm@gmail.com> & others * @version 1.0 */ class Our_Util_String { /** * Recursive Trimmer <img src="http://usage.cc/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> * http://php.net/manual/en/function.trim.php * * @param mixed $arr * @param string $charlist * @return mixed */ function trim($arr, $charlist = ' ') { if (is_string($arr)) { return trim($arr, $charlist); } elseif (is_array($arr)) { foreach($arr as $key => $value){ if (is_array($value)) { $result[$key] = self::trim($value, $charlist); } else { $result[$key] = trim($value, $charlist); } } return $result; } else { return $arr; } } } ?>
PHP
Published at DZone with permission of Svetoslav Marinov, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
How To Become a 10x Dev: An Essential Guide
-
The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables
-
Working on an Unfamiliar Codebase
-
How To Scan and Validate Image Uploads in Java
Comments