mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-23 07:27:13 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user