From a3976742d69aebc874075d95a183e864c97cfb9c Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 3 Jan 2025 18:30:27 -0500 Subject: [PATCH] Add recursive array conversion in RpcResponse::convertToArray --- src/Socialbox/Objects/RpcResponse.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Socialbox/Objects/RpcResponse.php b/src/Socialbox/Objects/RpcResponse.php index 2e56751..2ec8238 100644 --- a/src/Socialbox/Objects/RpcResponse.php +++ b/src/Socialbox/Objects/RpcResponse.php @@ -55,6 +55,26 @@ return $data->toArray(); } + // If the data is an array, recursively call this function on each element + if(is_array($data)) + { + foreach($data as $key => $value) + { + if(is_array($value)) + { + $data[$key] = $this->convertToArray($value); + } + elseif($value instanceof SerializableInterface) + { + $data[$key] = $value->toArray(); + } + else + { + $data[$key] = $value; + } + } + } + return $data; }