How To Strip Whitespace From An Array Using Php?

You tin flame strip white infinite from an array yesteryear using a combination of next php functions.

  • array_filter — Filters elements of an array using a callback function
  • array_map — Applies the callback to the elements of the given arrays
  • trim — Strip whitespace (or other characters) from the outset together with destination of a string

Syntax
 array_filter(array_map('trim', $array)); 
This volition withdraw all whitespace from the sides (but non betwixt chars). And it volition withdraw whatever entries of input equal to FALSE (e.g. 0, 0.00, null, false, …)

For example
 $array = array(' foo ', 'bar ', ' baz', '    ', '', 'foo bar'); $array = array_filter(array_map('trim', $array)); print_r($array);  // Output Array (     [0] => foo     [1] => bar     [2] => baz     [5] => foo bar ) 

Source: http://stackoverflow.com/a/3384083
Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?