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