Benutzer-Werkzeuge

Webseiten-Werkzeuge


snippets:recombine

Safely implode multi-dimensional arrays

Based on http://de3.php.net/manual/en/function.implode.php#94688

/**
 * Casts empty values aside and works both with one- and multi-dimensional arrays
 *
 * @author Fabian Wolf
 * @link http://fwolf.info/
 * @link http://de3.php.net/manual/en/function.implode.php#94688
 */
 
function recombine( $glue, $pieces ) {
	$string = '';
 
	if(is_array($pieces) != false){
		reset($pieces);
 
		while(list($key, $value) = each($pieces))
		{
			if( !empty($value) ) { // avoid empty values
				$string .= $glue . recombine($glue, $value);
			}
		}
	}
	else
	{
		return $pieces;
	}
 
	return trim($string, $glue);
}
snippets/recombine.txt · Zuletzt geändert: 27.03.2010 16:29 von fwolf