| @@ 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)) { |
|
| 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. |
|
| @@ 3119-3135 (lines=17) @@ | ||
| 3116 | * @return static |
|
| 3117 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 3118 | */ |
|
| 3119 | public function prependToEachKey($suffix): self |
|
| 3120 | { |
|
| 3121 | // init |
|
| 3122 | $result = []; |
|
| 3123 | ||
| 3124 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3125 | if ($item instanceof self) { |
|
| 3126 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 3127 | } elseif (\is_array($item)) { |
|
| 3128 | $result[$key] = self::create( |
|
| 3129 | $item, |
|
| 3130 | $this->iteratorClass, |
|
| 3131 | false |
|
| 3132 | )->prependToEachKey($suffix) |
|
| 3133 | ->toArray(); |
|
| 3134 | } else { |
|
| 3135 | $result[$key . $suffix] = $item; |
|
| 3136 | } |
|
| 3137 | } |
|
| 3138 | ||