Arrays > minor refactoring

This commit is contained in:
Meritoo
2018-07-01 17:43:06 +02:00
parent 1431fd9935
commit 848adef015
2 changed files with 53 additions and 46 deletions

View File

@@ -4,6 +4,7 @@ Common and useful classes, methods, exceptions etc.
# 0.0.21 # 0.0.21
1. Composer > require ext-pcre 1. Composer > require ext-pcre
2. Arrays > minor refactoring
# 0.0.20 # 0.0.20

View File

@@ -673,7 +673,7 @@ class Arrays
return null; return null;
} }
$effect = $array; $effect = &$array;
ksort($effect, $sortFlags); ksort($effect, $sortFlags);
foreach ($effect as &$value) { foreach ($effect as &$value) {
@@ -822,13 +822,20 @@ class Arrays
*/ */
public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '') public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '')
{ {
$paths = []; /*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return [];
}
if (!empty($array)) {
if (!empty($stopIfMatchedBy)) { if (!empty($stopIfMatchedBy)) {
$stopIfMatchedBy = self::makeArray($stopIfMatchedBy); $stopIfMatchedBy = self::makeArray($stopIfMatchedBy);
} }
$paths = [];
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
$path = $key; $path = $key;
$stopRecursion = false; $stopRecursion = false;
@@ -877,7 +884,6 @@ class Arrays
$paths += $recursivePaths; $paths += $recursivePaths;
} }
} }
}
return $paths; return $paths;
} }