From 405fe950b88fffd14929b1bbf3b7478236500f67 Mon Sep 17 00:00:00 2001 From: Steffen Lange Date: Sun, 24 Oct 2021 00:26:57 +0200 Subject: [PATCH] PatchBase: JSON iterator returns first hit --- PatchBase.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/PatchBase.php b/PatchBase.php index a787d21..cda32d9 100644 --- a/PatchBase.php +++ b/PatchBase.php @@ -74,10 +74,12 @@ abstract class PatchBase { return false; } protected function parse_json(string $key, string $re = '/(.*)/') : bool { - $flat = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data))); - if (!empty($flat[$key])) { - $this->data = $flat[$key]; - return $this->parse($re); + $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data)); + foreach ($it as $k => $v) { + if ($key == $k) { + $this->data = $v; + return $this->parse($re); + } } return false; }