I solved it My bad, that was becasue of using exit() inside the foreach the code does not continue and only performs the first element,
$checkbox = $_POST['referenceID'];
$response = []; //All Result
foreach ($checkbox as $chk) {
$stmt = $con->prepare(
"SELECT * FROM `table` WHERE `ref` = :referenceid"
);
$stmt->execute([':referenceid' => $chk]);
$stmt = $stmt->fetchAll();
$i = 1;
foreach ($stmt as $data) {
$response[] = [
"slno" => $i,
"name" => $data['name'],
"orderid" => $data['address'],
];
$i++;
}
}
echo json_encode($response);