-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_sort.php
More file actions
56 lines (46 loc) · 1.39 KB
/
_sort.php
File metadata and controls
56 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/main/blob/master/LICENSE
*/
namespace Quid\Main\Map;
use Quid\Base;
use Quid\Main;
// _sort
// trait that provides methods to change the order of entries within the collection
trait _sort
{
// sort
// sort les clés de la map
final public function sort($sort=true,int $type=SORT_FLAG_CASE | SORT_NATURAL):Main\Map
{
$this->checkAllowed('sort');
$return = $this->onPrepareThis('sort');
$data =& $return->arr();
$data = Base\Arr::keysSort($data,$sort,$type);
return $return;
}
// shuffle
// shuffle les valeurs de la map tout en conservant les clés
final public function shuffle():Main\Map
{
$this->checkAllowed('sort');
$return = $this->onPrepareThis('sort');
$data =& $return->arr();
$data = Base\Arr::shuffle($data,true);
return $return;
}
// reverse
// reverse l'ordre des valeurs de la map tout en conservant les clés
final public function reverse(bool $preserve=true):Main\Map
{
$this->checkAllowed('sort');
$return = $this->onPrepareThis('sort');
$data =& $return->arr();
$data = Base\Arr::reverse($data,true);
return $return;
}
}
?>