Re: Removing Spaces from Array Values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Lucas wrote:
foreach ( $someArray AS $k => $v ) {

$someArray[$k] = preg_replace('!\s!', '', $v); // Removes white space ' ', \n, \r\n, etc...

    $someArray[$k] = str_replace(' ', '', $v);    // Removes only spaces

}


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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux