From f1d4192ae7c72919f21d8379abf7acaa9f14b3cf Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 21 Oct 2015 12:20:45 +0200 Subject: [PATCH] Introduce a resolve() function to Utils, used by Group and User to access an array using dot notation --- system/src/Grav/Common/Utils.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index c0b15af44..9f21c315c 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -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; + } + }