| @@ 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. |
|
| @@ 3024-3040 (lines=17) @@ | ||
| 3021 | * @return static |
|
| 3022 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 3023 | */ |
|
| 3024 | public function prependToEachKey($suffix): self |
|
| 3025 | { |
|
| 3026 | // init |
|
| 3027 | $result = []; |
|
| 3028 | ||
| 3029 | foreach ($this->getGenerator() as $key => $item) { |
|
| 3030 | if ($item instanceof self) { |
|
| 3031 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 3032 | } elseif (\is_array($item)) { |
|
| 3033 | $result[$key] = self::create( |
|
| 3034 | $item, |
|
| 3035 | $this->iteratorClass, |
|
| 3036 | false |
|
| 3037 | )->prependToEachKey($suffix) |
|
| 3038 | ->toArray(); |
|
| 3039 | } else { |
|
| 3040 | $result[$key . $suffix] = $item; |
|
| 3041 | } |
|
| 3042 | } |
|
| 3043 | ||