| @@ 2763-2779 (lines=17) @@ | ||
| 2760 | * @return static |
|
| 2761 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 2762 | */ |
|
| 2763 | public function prependToEachKey($suffix): self |
|
| 2764 | { |
|
| 2765 | // init |
|
| 2766 | $result = []; |
|
| 2767 | ||
| 2768 | foreach ($this->getGenerator() as $key => $item) { |
|
| 2769 | if ($item instanceof self) { |
|
| 2770 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 2771 | } elseif (\is_array($item)) { |
|
| 2772 | $result[$key] = self::create( |
|
| 2773 | $item, |
|
| 2774 | $this->iteratorClass, |
|
| 2775 | false |
|
| 2776 | )->prependToEachKey($suffix) |
|
| 2777 | ->toArray(); |
|
| 2778 | } else { |
|
| 2779 | $result[$key . $suffix] = $item; |
|
| 2780 | } |
|
| 2781 | } |
|
| 2782 | ||
| @@ 672-690 (lines=19) @@ | ||
| 669 | * @return static |
|
| 670 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
| 671 | */ |
|
| 672 | public function appendToEachKey($prefix): self |
|
| 673 | { |
|
| 674 | // init |
|
| 675 | $result = []; |
|
| 676 | ||
| 677 | foreach ($this->getGenerator() as $key => $item) { |
|
| 678 | if ($item instanceof self) { |
|
| 679 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 680 | } elseif (\is_array($item)) { |
|
| 681 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 682 | ->appendToEachKey($prefix) |
|
| 683 | ->toArray(); |
|
| 684 | } else { |
|
| 685 | $result[$prefix . $key] = $item; |
|
| 686 | } |
|
| 687 | } |
|
| 688 | ||
| 689 | return self::create($result, $this->iteratorClass, false); |
|
| 690 | } |
|
| 691 | ||
| 692 | /** |
|
| 693 | * Add a prefix to each value. |
|