| @@ 687-705 (lines=19) @@ | ||
| 684 | * @return static |
|
| 685 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
| 686 | */ |
|
| 687 | public function appendToEachKey($prefix): self |
|
| 688 | { |
|
| 689 | // init |
|
| 690 | $result = []; |
|
| 691 | ||
| 692 | foreach ($this->getGenerator() as $key => $item) { |
|
| 693 | if ($item instanceof self) { |
|
| 694 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 695 | } elseif (\is_array($item) === true) { |
|
| 696 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 697 | ->appendToEachKey($prefix) |
|
| 698 | ->toArray(); |
|
| 699 | } else { |
|
| 700 | $result[$prefix . $key] = $item; |
|
| 701 | } |
|
| 702 | } |
|
| 703 | ||
| 704 | return self::create($result, $this->iteratorClass, false); |
|
| 705 | } |
|
| 706 | ||
| 707 | /** |
|
| 708 | * Add a prefix to each value. |
|
| @@ 3182-3207 (lines=26) @@ | ||
| 3179 | * @return static |
|
| 3180 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 3181 | */ |
|
| 3182 | public function prependToEachKey($suffix): self |
|
| 3183 | { |
|
| 3184 | // init |
|
| 3185 | $result = []; |
|
| 3186 | ||
| 3187 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3188 | if ($item instanceof self) { |
|
| 3189 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 3190 | } elseif (\is_array($item) === true) { |
|
| 3191 | $result[$key] = self::create( |
|
| 3192 | $item, |
|
| 3193 | $this->iteratorClass, |
|
| 3194 | false |
|
| 3195 | )->prependToEachKey($suffix) |
|
| 3196 | ->toArray(); |
|
| 3197 | } else { |
|
| 3198 | $result[$key . $suffix] = $item; |
|
| 3199 | } |
|
| 3200 | } |
|
| 3201 | ||
| 3202 | return self::create( |
|
| 3203 | $result, |
|
| 3204 | $this->iteratorClass, |
|
| 3205 | false |
|
| 3206 | ); |
|
| 3207 | } |
|
| 3208 | ||
| 3209 | /** |
|
| 3210 | * Add a suffix to each value. |
|