@@ 735-753 (lines=19) @@ | ||
732 | * @return static |
|
733 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
|
734 | */ |
|
735 | public function appendToEachKey($prefix): self |
|
736 | { |
|
737 | // init |
|
738 | $result = []; |
|
739 | ||
740 | foreach ($this->getGenerator() as $key => $item) { |
|
741 | if ($item instanceof self) { |
|
742 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
743 | } elseif (\is_array($item) === true) { |
|
744 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
745 | ->appendToEachKey($prefix) |
|
746 | ->toArray(); |
|
747 | } else { |
|
748 | $result[$prefix . $key] = $item; |
|
749 | } |
|
750 | } |
|
751 | ||
752 | return self::create($result, $this->iteratorClass, false); |
|
753 | } |
|
754 | ||
755 | /** |
|
756 | * Add a prefix to each value. |
|
@@ 3434-3459 (lines=26) @@ | ||
3431 | * @return static |
|
3432 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
|
3433 | */ |
|
3434 | public function prependToEachKey($suffix): self |
|
3435 | { |
|
3436 | // init |
|
3437 | $result = []; |
|
3438 | ||
3439 | foreach ($this->getGenerator() as $key => $item) { |
|
3440 | if ($item instanceof self) { |
|
3441 | $result[$key] = $item->prependToEachKey($suffix); |
|
3442 | } elseif (\is_array($item) === true) { |
|
3443 | $result[$key] = self::create( |
|
3444 | $item, |
|
3445 | $this->iteratorClass, |
|
3446 | false |
|
3447 | )->prependToEachKey($suffix) |
|
3448 | ->toArray(); |
|
3449 | } else { |
|
3450 | $result[$key . $suffix] = $item; |
|
3451 | } |
|
3452 | } |
|
3453 | ||
3454 | return self::create( |
|
3455 | $result, |
|
3456 | $this->iteratorClass, |
|
3457 | false |
|
3458 | ); |
|
3459 | } |
|
3460 | ||
3461 | /** |
|
3462 | * Add a suffix to each value. |