"https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/seleccionar", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($params), CURLOPT_HTTPHEADER => [ "token: e12e2dde0e95a32e274328fd274e07d53f127630c211d838efffacd3cafc4f14edf3f3de6a649eb23f98edf6a1863a008f60e78a316d4dec996b79aeea161a0c", "username: SGU_APSA_AUD_ASIST", "Content-Type: application/json" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) die("cURL Error #:$err"); $selectedData = json_decode($response, true); $rawInput = file_get_contents('php://input'); $input = json_decode($rawInput, true); // check for {collect: []} in raw input if (isset($input['collect']) && is_array($input['collect'])) { $collect = $input['collect']; $selectedData = array_map(function ($item) use ($collect) { return array_intersect_key($item, array_flip($collect)); }, $selectedData); // unique and distinct $selectedData = array_unique($selectedData, SORT_REGULAR); } else { // return invalid request error die($rawInput); } // Output the selected data directly header('Content-Type: application/json'); echo json_encode($selectedData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);