| @@ 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. |
|
| @@ 3170-3195 (lines=26) @@ | ||
| 3167 | * @return static |
|
| 3168 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 3169 | */ |
|
| 3170 | public function prependToEachKey($suffix): self |
|
| 3171 | { |
|
| 3172 | // init |
|
| 3173 | $result = []; |
|
| 3174 | ||
| 3175 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3176 | if ($item instanceof self) { |
|
| 3177 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 3178 | } elseif (\is_array($item) === true) { |
|
| 3179 | $result[$key] = self::create( |
|
| 3180 | $item, |
|
| 3181 | $this->iteratorClass, |
|
| 3182 | false |
|
| 3183 | )->prependToEachKey($suffix) |
|
| 3184 | ->toArray(); |
|
| 3185 | } else { |
|
| 3186 | $result[$key . $suffix] = $item; |
|
| 3187 | } |
|
| 3188 | } |
|
| 3189 | ||
| 3190 | return self::create( |
|
| 3191 | $result, |
|
| 3192 | $this->iteratorClass, |
|
| 3193 | false |
|
| 3194 | ); |
|
| 3195 | } |
|
| 3196 | ||
| 3197 | /** |
|
| 3198 | * Add a suffix to each value. |
|