public static function implodeAssociativeArray($array, $separator = '=', $glue = ', ')
{
// build a new array with joined keys and values
$tmpArray = null;
foreach ($array as $key => $value) {
if ($value instanceof DateTime) {
$value = $value->format('r');
}
$tmpArray[] = $key . $separator . $value;
}
// implode and return the new array
return is_array($tmpArray) ? implode($glue, $tmpArray) : false;
}
public function testimplodeAssociativeArray() { $array = ['test1' => 'val1', 'test2' => 'val2', 'test3' => new DateTime('2015-05-15 17:21:00')]; $string = Braintree\Util::implodeAssociativeArray($array); $this->assertEquals('test1=val1, test2=val2, test3=Fri, 15 May 2015 17:21:00 +0000', $string); }