| @@ 3011-3026 (lines=16) @@ | ||
| 3008 | * @return static |
|
| 3009 | * <p>(Immutable)</p> |
|
| 3010 | */ |
|
| 3011 | public function moveElementToFirstPlace($key): self |
|
| 3012 | { |
|
| 3013 | $array = $this->getArray(); |
|
| 3014 | ||
| 3015 | if ($this->offsetExists($key)) { |
|
| 3016 | $tmpValue = $this->get($key); |
|
| 3017 | unset($array[$key]); |
|
| 3018 | $array = [$key => $tmpValue] + $array; |
|
| 3019 | } |
|
| 3020 | ||
| 3021 | return static::create( |
|
| 3022 | $array, |
|
| 3023 | $this->iteratorClass, |
|
| 3024 | false |
|
| 3025 | ); |
|
| 3026 | } |
|
| 3027 | ||
| 3028 | /** |
|
| 3029 | * Move an array element to the last place. |
|
| @@ 3039-3054 (lines=16) @@ | ||
| 3036 | * @return static |
|
| 3037 | * <p>(Immutable)</p> |
|
| 3038 | */ |
|
| 3039 | public function moveElementToLastPlace($key): self |
|
| 3040 | { |
|
| 3041 | $array = $this->getArray(); |
|
| 3042 | ||
| 3043 | if ($this->offsetExists($key)) { |
|
| 3044 | $tmpValue = $this->get($key); |
|
| 3045 | unset($array[$key]); |
|
| 3046 | $array += [$key => $tmpValue]; |
|
| 3047 | } |
|
| 3048 | ||
| 3049 | return static::create( |
|
| 3050 | $array, |
|
| 3051 | $this->iteratorClass, |
|
| 3052 | false |
|
| 3053 | ); |
|
| 3054 | } |
|
| 3055 | ||
| 3056 | /** |
|
| 3057 | * Get a subset of the items from the given array. |
|