| @@ 630-648 (lines=19) @@ | ||
| 627 | * @return static |
|
| 628 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
| 629 | */ |
|
| 630 | public function appendToEachKey($prefix) |
|
| 631 | { |
|
| 632 | // init |
|
| 633 | $result = []; |
|
| 634 | ||
| 635 | foreach ($this->getGenerator() as $key => $item) { |
|
| 636 | if ($item instanceof self) { |
|
| 637 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 638 | } elseif (\is_array($item)) { |
|
| 639 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 640 | ->appendToEachKey($prefix) |
|
| 641 | ->toArray(); |
|
| 642 | } else { |
|
| 643 | $result[$prefix . $key] = $item; |
|
| 644 | } |
|
| 645 | } |
|
| 646 | ||
| 647 | return self::create($result, $this->iteratorClass, false); |
|
| 648 | } |
|
| 649 | ||
| 650 | /** |
|
| 651 | * Add a prefix to each value. |
|
| @@ 2990-3007 (lines=18) @@ | ||
| 2987 | * @return static |
|
| 2988 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
| 2989 | */ |
|
| 2990 | public function prependToEachKey($suffix) |
|
| 2991 | { |
|
| 2992 | // init |
|
| 2993 | $result = []; |
|
| 2994 | ||
| 2995 | foreach ($this->getGenerator() as $key => $item) { |
|
| 2996 | if ($item instanceof self) { |
|
| 2997 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 2998 | } elseif (\is_array($item)) { |
|
| 2999 | $result[$key] = self::create($item, $this->iteratorClass, false)->prependToEachKey($suffix)->toArray(); |
|
| 3000 | } else { |
|
| 3001 | $result[$key . $suffix] = $item; |
|
| 3002 | } |
|
| 3003 | } |
|
| 3004 | ||
| 3005 | return self::create($result, $this->iteratorClass, false); |
|
| 3006 | } |
|
| 3007 | ||
| 3008 | /** |
|
| 3009 | * Add a suffix to each value. |
|
| 3010 | * |
|