Add implode_with_keys function
This commit is contained in:
parent
43a467b15a
commit
15c1daabb5
1 changed files with 16 additions and 0 deletions
|
@ -328,4 +328,20 @@ function format_duration($value, $unit=null, $precision=null, $separator=null) {
|
||||||
return implode(is_null($separator)?' ':strval($separator), $result);
|
return implode(is_null($separator)?' ':strval($separator), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implode array's keys & values (ex: 'k1=v1, k2=v2, ...')
|
||||||
|
* @param array<string|int,mixed> $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
|
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
|
||||||
|
|
Loading…
Reference in a new issue