| @@ 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. |
|
| @@ 3136-3161 (lines=26) @@ | ||
| 3133 | * @return static |
|
| 3134 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 3135 | */ |
|
| 3136 | public function prependToEachKey($suffix): self |
|
| 3137 | { |
|
| 3138 | // init |
|
| 3139 | $result = []; |
|
| 3140 | ||
| 3141 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3142 | if ($item instanceof self) { |
|
| 3143 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 3144 | } elseif (\is_array($item) === true) { |
|
| 3145 | $result[$key] = self::create( |
|
| 3146 | $item, |
|
| 3147 | $this->iteratorClass, |
|
| 3148 | false |
|
| 3149 | )->prependToEachKey($suffix) |
|
| 3150 | ->toArray(); |
|
| 3151 | } else { |
|
| 3152 | $result[$key . $suffix] = $item; |
|
| 3153 | } |
|
| 3154 | } |
|
| 3155 | ||
| 3156 | return self::create( |
|
| 3157 | $result, |
|
| 3158 | $this->iteratorClass, |
|
| 3159 | false |
|
| 3160 | ); |
|
| 3161 | } |
|
| 3162 | ||
| 3163 | /** |
|
| 3164 | * Add a suffix to each value. |
|