Re: Removing Spaces from Array Values
| From: | Arpad Ray | Date: | Tue, 03 Jul 2007 22:28:45 +0000 |
| Subject: | Re: Removing Spaces from Array Values | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258207@lists.php.net to get a copy of this message | ||
Jim Lucas wrote:
foreach ( $someArray AS $k => $v ) {str_replace() also operates on arrays so there's no need for the loop: $someArray = str_replace(' ', '', $someArray); And if you want to replace all whitespace: $space = array(' ', "\t", "\n", "\r", "\x0B", "\x0C"); $someArray = str_replace($space, '', $someArray); Arpad$someArray[$k] = preg_replace('!\s!', '', $v); // Removes white space ' ', \n, \r\n, etc...$someArray[$k] = str_replace(' ', '', $v); // Removes only spaces}