method retrieveArrayVar documentation in bbn\X
Retrieves values from the given array based on the given keys.
Example
$arr = ['a' => ['e' => 33, 'f' => 'foo'], 'b' => 2, 'c' => 3, 'd' => ['g' => 11]];
X::retrieveArrayVar(['a', 'e'], $arr);
// (int) 33
X::retrieveArrayVar(['a', 'f'], $arr);
// (string) "foo"
X::retrieveArrayVar(['d'], $arr);
// (array) ['g' => 11]
function(array $props, array &$ar)
{
$cur = &$ar;
foreach ($props as $p) {
if (\is_array($cur) && array_key_exists($p, $cur)) {
$cur =& $cur[$p];
}
else{
throw new Exception("Impossible to find the value in the array");
}
}
return $cur;
}
Retrieves values from the given array based on the given keys. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions