php return json
// function to return JSON response, you can set cors, also give status & data via arguments
function json($status, $data) {
$cors = "*";
header("Access-Control-Allow-Origin: $cors");
header('Content-Type: application/json; charset=utf-8');
http_response_code($status);
echo json_encode($data);
}
// example
json(200, [
"status" => 200,
"message" => "action completed successfully",
"id" => 44236
]);