0)) { $isLastPage = false; $result .= json_encode(json_decode($answer, true)['viewedItems']) . ','; } else { $isLastPage = true; $result = substr($result, 0, -1); } curl_close($ch); $currentPage++; } if ($result !== '') { print_r($result . ']'); } else { http_response_code(404); die(); } } else { http_response_code(404); die(); }