| @@ 668-686 (lines=19) @@ | ||
| 665 | * @return static |
|
| 666 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
| 667 | */ |
|
| 668 | public function appendToEachKey($prefix): self |
|
| 669 | { |
|
| 670 | // init |
|
| 671 | $result = []; |
|
| 672 | ||
| 673 | foreach ($this->getGenerator() as $key => $item) { |
|
| 674 | if ($item instanceof self) { |
|
| 675 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 676 | } elseif (\is_array($item)) { |
|
| 677 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 678 | ->appendToEachKey($prefix) |
|
| 679 | ->toArray(); |
|
| 680 | } else { |
|
| 681 | $result[$prefix . $key] = $item; |
|
| 682 | } |
|
| 683 | } |
|
| 684 | ||
| 685 | return self::create($result, $this->iteratorClass, false); |
|
| 686 | } |
|
| 687 | ||
| 688 | /** |
|
| 689 | * Add a prefix to each value. |
|
| @@ 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 | ||