Add function

This commit is contained in:
Dennis Eichhorn 2017-10-23 17:31:05 +02:00
parent d73e65fd09
commit 19afa91ee7

View File

@ -74,7 +74,7 @@ class ArrayUtils
}
/**
* Check if needle exists in multidimensional array.
* Set element in array by path
*
* @param string $path Path to element
* @param array $data Array
@ -112,6 +112,29 @@ class ArrayUtils
return $data;
}
/**
* Get element of array by path
*
* @param string $path Path to element
* @param array $data Array
* @param string $delim Delimiter for path
*
* @return mixed
*
* @since 1.0.0
*/
public static function getArray(string $path, array $data, string $delim = '/')
{
$pathParts = explode($delim, trim($path, $delim));
$current = $data;
foreach ($pathParts as $key) {
$current = $current[$key];
}
return $current;
}
/**
* Check if needle exists in multidimensional array.
*