| @@ 3019-3034 (lines=16) @@ | ||
| 3016 | * @return static |
|
| 3017 | * <p>(Immutable)</p> |
|
| 3018 | */ |
|
| 3019 | public function moveElementToFirstPlace($key): self |
|
| 3020 | { |
|
| 3021 | $array = $this->getArray(); |
|
| 3022 | ||
| 3023 | if ($this->offsetExists($key)) { |
|
| 3024 | $tmpValue = $this->get($key); |
|
| 3025 | unset($array[$key]); |
|
| 3026 | $array = [$key => $tmpValue] + $array; |
|
| 3027 | } |
|
| 3028 | ||
| 3029 | return static::create( |
|
| 3030 | $array, |
|
| 3031 | $this->iteratorClass, |
|
| 3032 | false |
|
| 3033 | ); |
|
| 3034 | } |
|
| 3035 | ||
| 3036 | /** |
|
| 3037 | * Move an array element to the last place. |
|
| @@ 3047-3062 (lines=16) @@ | ||
| 3044 | * @return static |
|
| 3045 | * <p>(Immutable)</p> |
|
| 3046 | */ |
|
| 3047 | public function moveElementToLastPlace($key): self |
|
| 3048 | { |
|
| 3049 | $array = $this->getArray(); |
|
| 3050 | ||
| 3051 | if ($this->offsetExists($key)) { |
|
| 3052 | $tmpValue = $this->get($key); |
|
| 3053 | unset($array[$key]); |
|
| 3054 | $array += [$key => $tmpValue]; |
|
| 3055 | } |
|
| 3056 | ||
| 3057 | return static::create( |
|
| 3058 | $array, |
|
| 3059 | $this->iteratorClass, |
|
| 3060 | false |
|
| 3061 | ); |
|
| 3062 | } |
|
| 3063 | ||
| 3064 | /** |
|
| 3065 | * Get a subset of the items from the given array. |
|