[TYPO3-core] t3lib_div::trimExplode clean up

Dmitry Dulepov [typo3] dmitry at typo3.org
Mon Sep 10 16:04:28 CEST 2007


Martin Kutschker wrote:
> Again deliberately done for maximum performance. We save the duplication 
> of the array ($arr = $arr) that way.

You can get rid of last line in the function. And you can remove "else 
{" and "}" because "if" returns unconditionally. This way it is even 
smaller but speed is the same.

function trimExplode($delim, $string, $onlyNonEmptyValues=0)	{
	$array = explode($delim, $string);
	if ($onlyNonEmptyValues) {
		$new_array = array();
		foreach($array as $index => $value) {
			$value = trim($value);
			if ($value != '') {
				$new_array[] = $value;
			}
		}
		return $new_array;
	}
	foreach($array as $key => &$value) {
		$value = trim($value);
	}
	return $array;
}

-- 
Dmitry Dulepov
TYPO3 freelancer / TYPO3 core team member
Web: http://typo3bloke.net/
Skype: callto:liels_bugs


More information about the TYPO3-team-core mailing list