Fixed issue when trying to check if a multidimensional array is dirty… (#19272)

* Fixed issue when trying to check if a multidimensional array is dirty attribute or not

* fixed issue in logic and added test

* Updated test to only support PHP 7 and above

* Code refactoring

* Updated Test Cases

* Update framework/helpers/BaseArrayHelper.php

Co-authored-by: Bizley <pawel@positive.codes>

* Added to CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Maher Al Ghoul <maher.gh@opensooq.com>
Co-authored-by: Bizley <pawel@positive.codes>
Co-authored-by: Maher Al Ghoul <maher@rufoof.com>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Co-authored-by: Maher Al Ghoul <Maher.AlGhoul@opensooq.com>
This commit is contained in:
Maher Al Ghoul
2022-04-18 14:41:20 +03:00
committed by GitHub
parent 8046d3a50f
commit 0f004db99b
4 changed files with 110 additions and 2 deletions

View File

@@ -7,9 +7,9 @@
namespace yii\helpers;
use Yii;
use ArrayAccess;
use Traversable;
use Yii;
use yii\base\Arrayable;
use yii\base\InvalidArgumentException;
@@ -999,4 +999,29 @@ class BaseArrayHelper
return $result;
}
/**
* Sorts array recursively.
*
* @param array $array An array passing by reference.
* @param callable|null $sorter The array sorter. If omitted, sort index array by values, sort assoc array by keys.
* @return array
*/
public static function recursiveSort(array &$array, $sorter = null)
{
foreach ($array as &$value) {
if (is_array($value)) {
self::recursiveSort($value, $sorter);
}
}
unset($value);
if ($sorter === null) {
$sorter = static::isIndexed($array) ? 'sort' : 'ksort';
}
call_user_func_array($sorter, [&$array]);
return $array;
}
}