@@ 974-992 (lines=19) @@ | ||
971 | * @psalm-return static<TKey,T> |
|
972 | * @psalm-mutation-free |
|
973 | */ |
|
974 | public function appendToEachKey($prefix): self |
|
975 | { |
|
976 | // init |
|
977 | $result = []; |
|
978 | ||
979 | foreach ($this->getGenerator() as $key => $item) { |
|
980 | if ($item instanceof self) { |
|
981 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
982 | } elseif (\is_array($item) === true) { |
|
983 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
984 | ->appendToEachKey($prefix) |
|
985 | ->toArray(); |
|
986 | } else { |
|
987 | $result[$prefix . $key] = $item; |
|
988 | } |
|
989 | } |
|
990 | ||
991 | return self::create($result, $this->iteratorClass, false); |
|
992 | } |
|
993 | ||
994 | /** |
|
995 | * Add a prefix to each value. |
|
@@ 4301-4326 (lines=26) @@ | ||
4298 | * @psalm-return static<TKey,T> |
|
4299 | * @psalm-mutation-free |
|
4300 | */ |
|
4301 | public function prependToEachKey($suffix): self |
|
4302 | { |
|
4303 | // init |
|
4304 | $result = []; |
|
4305 | ||
4306 | foreach ($this->getGenerator() as $key => $item) { |
|
4307 | if ($item instanceof self) { |
|
4308 | $result[$key] = $item->prependToEachKey($suffix); |
|
4309 | } elseif (\is_array($item) === true) { |
|
4310 | $result[$key] = self::create( |
|
4311 | $item, |
|
4312 | $this->iteratorClass, |
|
4313 | false |
|
4314 | )->prependToEachKey($suffix) |
|
4315 | ->toArray(); |
|
4316 | } else { |
|
4317 | $result[$key . $suffix] = $item; |
|
4318 | } |
|
4319 | } |
|
4320 | ||
4321 | return self::create( |
|
4322 | $result, |
|
4323 | $this->iteratorClass, |
|
4324 | false |
|
4325 | ); |
|
4326 | } |
|
4327 | ||
4328 | /** |
|
4329 | * Add a suffix to each value. |