"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: 64293fb86c06e45331ab9963822762f77b9c403ca949adcc31286d550e902fff202e4c69d1574b2082ecf0b3a28b6cfd4d88b3a7d2c2ab7d329666b9a527fb1b", "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);