Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Example Interest Rates: Home Loan Variable: 1.89% (1.9%*) • Home Loan Fixed: 1.84% (2.11%*) • Fixed: 1.84% (2.11%*) • Variable: 1.89% (1.9%*) • Investment IO: 2.05% (4.36%*) • Investment PI: 1.58% (2.72%*)

Trim Values in an Array or Multidimensional Array

This is a handy reference for trimming values in an associative array. While there's any number of ways to achieve the result, this works nicely.

1
<?php 
2
$results = array_map(array_map('trim', $results));

A multidimensional array is immune to the above code. The following function will work on a string or array.

1
<?php 
2
/*
3
 Trim Values in an Array or Multidimensional Array
4
 http://www.beliefmedia.com/code/php-snippets/trim-array-values
5
*/
6
 
7
function beliefmedia_trim($data) {
8
 if ($data == null) return null;
9
 
10
 if (is_array($data)) {
11
   return array_map('beliefmedia_trim_array', $data);
12
 } else return trim($data);
13
}

Got an easier way? Let us know.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Washington)

  Want to have a chat?
 

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment