mirror of
https://github.com/getgrav/grav.git
synced 2026-07-06 10:29:30 +02:00
Introduce a resolve() function to Utils, used by Group and User to access an array using dot notation
This commit is contained in:
@@ -377,4 +377,23 @@ abstract class Utils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of an array using dot notation
|
||||
*/
|
||||
public static function resolve(array $array, $path, $default = null)
|
||||
{
|
||||
$current = $array;
|
||||
$p = strtok($path, '.');
|
||||
|
||||
while ($p !== false) {
|
||||
if (!isset($current[$p])) {
|
||||
return $default;
|
||||
}
|
||||
$current = $current[$p];
|
||||
$p = strtok('.');
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user