| @@ 3041-3056 (lines=16) @@ | ||
| 3038 | * @return static |
|
| 3039 | * <p>(Immutable)</p> |
|
| 3040 | */ |
|
| 3041 | public function moveElementToFirstPlace($key): self |
|
| 3042 | { |
|
| 3043 | $array = $this->getArray(); |
|
| 3044 | ||
| 3045 | if ($this->offsetExists($key)) { |
|
| 3046 | $tmpValue = $this->get($key); |
|
| 3047 | unset($array[$key]); |
|
| 3048 | $array = [$key => $tmpValue] + $array; |
|
| 3049 | } |
|
| 3050 | ||
| 3051 | return static::create( |
|
| 3052 | $array, |
|
| 3053 | $this->iteratorClass, |
|
| 3054 | false |
|
| 3055 | ); |
|
| 3056 | } |
|
| 3057 | ||
| 3058 | /** |
|
| 3059 | * Move an array element to the last place. |
|
| @@ 3069-3084 (lines=16) @@ | ||
| 3066 | * @return static |
|
| 3067 | * <p>(Immutable)</p> |
|
| 3068 | */ |
|
| 3069 | public function moveElementToLastPlace($key): self |
|
| 3070 | { |
|
| 3071 | $array = $this->getArray(); |
|
| 3072 | ||
| 3073 | if ($this->offsetExists($key)) { |
|
| 3074 | $tmpValue = $this->get($key); |
|
| 3075 | unset($array[$key]); |
|
| 3076 | $array += [$key => $tmpValue]; |
|
| 3077 | } |
|
| 3078 | ||
| 3079 | return static::create( |
|
| 3080 | $array, |
|
| 3081 | $this->iteratorClass, |
|
| 3082 | false |
|
| 3083 | ); |
|
| 3084 | } |
|
| 3085 | ||
| 3086 | /** |
|
| 3087 | * Get a subset of the items from the given array. |
|