Site du proximo, utilisé pour gérer le stock.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RecursiveSortingTrait.php 771B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace OpenFoodFacts;
  3. /**
  4. * Trait RecursiveSortingTrait
  5. */
  6. trait RecursiveSortingTrait
  7. {
  8. /**
  9. * @param array $arr
  10. * @return bool
  11. */
  12. private function isAssoc(array $arr): bool
  13. {
  14. return array_keys($arr) !== range(0, count($arr) - 1);
  15. }
  16. /**
  17. * Sorts referenced array of arrays in a recursive way for better understandability
  18. * @param array $arr
  19. * @see ksort
  20. * @see asort
  21. */
  22. public function recursiveSortArray(array &$arr): void
  23. {
  24. if ($this->isAssoc($arr)) {
  25. ksort($arr);
  26. } else {
  27. asort($arr);
  28. }
  29. foreach ($arr as &$a) {
  30. if (is_array($a)) {
  31. $this->recursiveSortArray($a);
  32. }
  33. }
  34. }
  35. }