| @@ 695-713 (lines=19) @@ | ||
| 692 | * @return static |
|
| 693 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
| 694 | */ |
|
| 695 | public function appendToEachKey($prefix): self |
|
| 696 | { |
|
| 697 | // init |
|
| 698 | $result = []; |
|
| 699 | ||
| 700 | foreach ($this->getGenerator() as $key => $item) { |
|
| 701 | if ($item instanceof self) { |
|
| 702 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 703 | } elseif (\is_array($item) === true) { |
|
| 704 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 705 | ->appendToEachKey($prefix) |
|
| 706 | ->toArray(); |
|
| 707 | } else { |
|
| 708 | $result[$prefix . $key] = $item; |
|
| 709 | } |
|
| 710 | } |
|
| 711 | ||
| 712 | return self::create($result, $this->iteratorClass, false); |
|
| 713 | } |
|
| 714 | ||
| 715 | /** |
|
| 716 | * Add a prefix to each value. |
|
| @@ 3144-3169 (lines=26) @@ | ||
| 3141 | * @return static |
|
| 3142 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 3143 | */ |
|
| 3144 | public function prependToEachKey($suffix): self |
|
| 3145 | { |
|
| 3146 | // init |
|
| 3147 | $result = []; |
|
| 3148 | ||
| 3149 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3150 | if ($item instanceof self) { |
|
| 3151 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 3152 | } elseif (\is_array($item) === true) { |
|
| 3153 | $result[$key] = self::create( |
|
| 3154 | $item, |
|
| 3155 | $this->iteratorClass, |
|
| 3156 | false |
|
| 3157 | )->prependToEachKey($suffix) |
|
| 3158 | ->toArray(); |
|
| 3159 | } else { |
|
| 3160 | $result[$key . $suffix] = $item; |
|
| 3161 | } |
|
| 3162 | } |
|
| 3163 | ||
| 3164 | return self::create( |
|
| 3165 | $result, |
|
| 3166 | $this->iteratorClass, |
|
| 3167 | false |
|
| 3168 | ); |
|
| 3169 | } |
|
| 3170 | ||
| 3171 | /** |
|
| 3172 | * Add a suffix to each value. |
|