note 103278 deleted from function.trim by hholzgra

From: Date: Thu, 02 Aug 2012 12:32:10 +0000
Subject: note 103278 deleted from function.trim by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189677@lists.php.net to get a copy of this message
Note Submitter: akarmenia at gmail dot com ---- Here's a function to trim strings recursively within an array. <?php // Trim a string or an array of strings recursively function trim_r($array) { if (is_string($array)) { return trim($array); } else if (!is_array($array)) { return ''; } $keys = array_keys($array); for ($i=0; $i<count($keys); $i++) { $key = $keys[$i]; if ( is_array($array[$key]) ) { $array[$key] = trim_r($array[$key]); } else if ( is_string($array[$key]) ) { $array[$key] = trim($array[$key]); } } return $array; } // Test $a = array(' cat ', ' dog ' => ' mouse ', 234); print_r(trim_r($a)); ?> Array ( [0] => cat [ dog ] => mouse [1] => 234 )

« previous php.notes (#189677) next »