| @@ 693-711 (lines=19) @@ | ||
| 690 | * @return static |
|
| 691 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
| 692 | */ |
|
| 693 | public function appendToEachKey($prefix): self |
|
| 694 | { |
|
| 695 | // init |
|
| 696 | $result = []; |
|
| 697 | ||
| 698 | foreach ($this->getGenerator() as $key => $item) { |
|
| 699 | if ($item instanceof self) { |
|
| 700 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 701 | } elseif (\is_array($item)) { |
|
| 702 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 703 | ->appendToEachKey($prefix) |
|
| 704 | ->toArray(); |
|
| 705 | } else { |
|
| 706 | $result[$prefix . $key] = $item; |
|
| 707 | } |
|
| 708 | } |
|
| 709 | ||
| 710 | return self::create($result, $this->iteratorClass, false); |
|
| 711 | } |
|
| 712 | ||
| 713 | /** |
|
| 714 | * Add a prefix to each value. |
|
| @@ 2822-2838 (lines=17) @@ | ||
| 2819 | * @return static |
|
| 2820 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 2821 | */ |
|
| 2822 | public function prependToEachKey($suffix): self |
|
| 2823 | { |
|
| 2824 | // init |
|
| 2825 | $result = []; |
|
| 2826 | ||
| 2827 | foreach ($this->getGenerator() as $key => $item) { |
|
| 2828 | if ($item instanceof self) { |
|
| 2829 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 2830 | } elseif (\is_array($item)) { |
|
| 2831 | $result[$key] = self::create( |
|
| 2832 | $item, |
|
| 2833 | $this->iteratorClass, |
|
| 2834 | false |
|
| 2835 | )->prependToEachKey($suffix) |
|
| 2836 | ->toArray(); |
|
| 2837 | } else { |
|
| 2838 | $result[$key . $suffix] = $item; |
|
| 2839 | } |
|
| 2840 | } |
|
| 2841 | ||