1 | <?php |
||
17 | trait SequentialOrderTrait |
||
18 | { |
||
19 | /** |
||
20 | * @param array $sourceArray The source array which the target is to be inserted into. The |
||
21 | * key represents a unique identifier, while the value is the sort order. |
||
22 | * |
||
23 | * As an example if this is the $sourceArray |
||
24 | * |
||
25 | * ``` |
||
26 | * [ |
||
27 | * 111 => 1, |
||
28 | * 343 => 2, |
||
29 | * 545 => 3, |
||
30 | * 'foo' => 4, |
||
31 | * 'bar' => 5 |
||
32 | * ] |
||
33 | * ``` |
||
34 | * |
||
35 | * And your $targetKey is 'fooBar' with a $targetOrder of 4, the result would be |
||
36 | * |
||
37 | * ``` |
||
38 | * [ |
||
39 | * 111 => 1, |
||
40 | * 343 => 2, |
||
41 | * 545 => 3, |
||
42 | * 'fooBar' => 4, |
||
43 | * 'foo' => 5, |
||
44 | * 'bar' => 6 |
||
45 | * ] |
||
46 | * ``` |
||
47 | * |
||
48 | * @param string|int $targetKey |
||
49 | * @param int $targetOrder |
||
50 | * @return array|bool |
||
51 | */ |
||
52 | protected function insertSequential(array $sourceArray, $targetKey, int $targetOrder) |
||
101 | |||
102 | /** |
||
103 | * @param array $sourceArray |
||
104 | */ |
||
105 | private function ensureSequential(array &$sourceArray) |
||
116 | } |
||
117 |