Braintree\Util::implodeAssociativeArray PHP Method

implodeAssociativeArray() public static method

public static implodeAssociativeArray ( array $array, string $separator = '=', string $glue = ', ' ) : boolean
$array array associative array to implode
$separator string (optional, defaults to =)
$glue string (optional, defaults to ', ')
return boolean
    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;
    }

Usage Example

Beispiel #1
0
 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);
 }