Skip to content

Instantly share code, notes, and snippets.

@lightningspirit
Created May 5, 2014 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lightningspirit/64765f45558c43ab2f42 to your computer and use it in GitHub Desktop.
Save lightningspirit/64765f45558c43ab2f42 to your computer and use it in GitHub Desktop.
Array implode function
<?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