diff --git a/src/functions.php b/src/functions.php index c8ace34..fac5e37 100644 --- a/src/functions.php +++ b/src/functions.php @@ -328,4 +328,20 @@ function format_duration($value, $unit=null, $precision=null, $separator=null) { return implode(is_null($separator)?' ':strval($separator), $result); } +/** + * Implode array's keys & values (ex: 'k1=v1, k2=v2, ...') + * @param array $values Array to implode + * @param boolean $quoted Set to false to disable values quotting (optional, default: true) + * @param string $separator Values separator (opional, default: ", ") + * @param string $kv_separator Key/value separator (optional, default: "=") + * @return string Imploded array string + */ +function implode_with_keys($values, $quoted=true, $separator=', ', $kv_separator='=') { + $result = []; + $quoted = $quoted?'"':''; + foreach ($values as $key => $value) + $result[] = "$key$kv_separator$quoted$value$quoted"; + return implode($separator, $result); +} + # vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab