Created
May 5, 2014 22:47
-
-
Save lightningspirit/64765f45558c43ab2f42 to your computer and use it in GitHub Desktop.
Array implode function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( !function_exists( 'array_implode' ) ) : | |
/** | |
* Implode an array with the key and value pair giving | |
* a glue, a separator between pairs and the array to implode. | |
* @param string $glue The glue between key and value | |
* @param string $separator Separator between pairs | |
* @param array $array The array to implode | |
* @return string The imploded array | |
*/ | |
function array_implode( $glue, $separator, $array ) { | |
if ( ! is_array( $array ) ) | |
return $array; | |
$string = array(); | |
foreach ( $array as $key => $val ) { | |
if ( is_array( $val ) ) | |
$val = implode( ',', $val ); | |
$string[] = "{$key}{$glue}{$val}"; | |
} | |
return implode( $separator, $string ); | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment