mirror of
https://github.com/getgrav/grav.git
synced 2026-02-28 01:21:30 +01:00
Added Utils::arrayToQueryParams() to convert an array into query params
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# v1.7.7
|
||||
## mm/dd/2021
|
||||
|
||||
1. [](#new)
|
||||
* Added `Utils::arrayToQueryParams()` to convert an array into query params
|
||||
1. [](#improved)
|
||||
* Added original image support for all flex objects and media fields
|
||||
1. [](#bugfix)
|
||||
|
||||
@@ -1086,6 +1086,29 @@ abstract class Utils
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array into query params.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $prepend
|
||||
* @return array
|
||||
*/
|
||||
public static function arrayToQueryParams($array, $prepend = '')
|
||||
{
|
||||
$results = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$name = $prepend ? $prepend . '[' . $key . ']' : $key;
|
||||
|
||||
if (is_array($value)) {
|
||||
$results = array_merge($results, static::arrayToQueryParams($value, $name));
|
||||
} else {
|
||||
$results[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten an array
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user