public static function flattenAssocArray(
        array $array,
        $format,
        $glue = null,
        $escape = false
    ) {
        $pairs = [];
        foreach ($array as $key => $val) {
            if ($escape) {
                $key = self::escape($key);
                $val = self::escape($val);
            }
            $pairs[] = sprintf($format, $key, $val);
        }

        //Return array if no glue provided
        if ($glue === null) {
            return $pairs;
        } else {
            return implode($glue, $pairs);
        }
    }
public static function flattenAssocArray(
        array $array,
        $format,
        $glue = null,
        $escape = false
    ) {
        $pairs = [];
        foreach ($array as $key => $val) {
            if ($escape) {
                $key = self::escape($key);
                $val = self::escape($val);
            }
            $pairs[] = sprintf($format, $key, $val);
        }

        //Return array if no glue provided
        if ($glue === null) {
            return $pairs;
        } else {
            return implode($glue, $pairs);
        }
    }
public static function flattenAssocArray ( array $ array , $ format , $ glue = null , $ escape = false ) { $ pairs = [ ] ; foreach ( $ array as $ key => $ val ) { if ( $ escape ) { $ key = self :: escape ( $ key ) ; $ val = self :: escape ( $ val ) ; } $ pairs [ ] = sprintf ( $ format , $ key , $ val ) ; } //Return array if no glue provided if ( $ glue === null ) { return $ pairs ; } else { return implode ( $ glue , $ pairs ) ; } }
Generic function to flatten an associative array into an arbitrarily
delimited string.

@param array $array
@param string $format
@param string|null $glue
@param bool $escape
@return string|array if no glue provided, it won't be imploded
Generic function to flatten an associative array into an arbitrarily delimited string .