Introduce a resolve() function to Utils, used by Group and User to access an array using dot notation

This commit is contained in:
Flavio Copes
2015-10-21 12:20:45 +02:00
parent fb500d3e1c
commit f1d4192ae7

View File

@@ -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;
}
}