php trim alle elements in an array


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.