note 77573 modified in function.array-filter by thiago

From: Date: Tue, 22 Jul 2008 23:33:36 +0000
Subject: note 77573 modified in function.array-filter by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142577@lists.php.net to get a copy of this message
This function trims empty strings from the beginning and end of an array. It's useful when outputing plaintext files on a page and you want to skip empty lines at the beginning and end, but not within the text. <?php function array_trim($array) { while (strlen(reset($array)) === 0) { array_shift($array); } while (strlen(end($array)) === 0) { array_pop($array); } return $array; } ?> You might want to trim each element too. --was-- This function trims empty strings from the beginning and end of an array. It's useful when outputing plaintext files on a page and you want to skip empty lines at the beginning and end, but not within the text. function array_trim($array) { while (strlen(reset($array)) === 0) { array_shift($array); } while (strlen(end($array)) === 0) { array_pop($array); } return $array; } You might want to trim each element too. http://php.net/manual/en/function.array-filter.php

« previous php.notes (#142577) next »