Posted By

Knarf on 11/14/09


Tagged

php array trim


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Vordreller


php trim alle elements in an array


 / Published in: PHP
 

A function i made for running trim on all elements in an array

  1. /* - function trim_array() -
  2. *
  3. * A function for quicly triming all variables in an array
  4. *
  5. */
  6.  
  7. function trim_array($value)
  8. {
  9. foreach($value as $name => $item) { // Walk's trou the array
  10. if(is_array($item)) { // If the variable is an array:
  11. $tmp[$name] = trim_array($item); // - We need to trim that one first
  12. } else { // Else:
  13. $tmp[$name] = trim($item); // - Trims the variable
  14. }
  15. }
  16. return $tmp; // Return the trimed versjon of the array
  17. }

Report this snippet  

You need to login to post a comment.