First of all, I would recommend you to use prepared statements.
Second, you get your query as an array key cause result has no alias, so that's why you see it in your array.
Third, you don't really need EXISTS
here.
Forth, you don't need a loop here also:
$query = "SELECT COUNT(*) FROM wp_woocommerce_order_items as item_exists WHERE order_id = $sdata";
if ($result = mysqli_query($conn, $query)) {
$newArr = array();
$value = mysqli_fetch_object($result);
$newArr[] = (bool) $value->item_exists;
echo json_encode($newArr); // get all products in json format.
}
Using prepared statements:
$stmt = $mysqli->prepare('SELECT COUNT(*) as item_exists FROM wp_woocommerce_order_items WHERE order_id = ?');
$stmt->bind_param("i", $sdata);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$stmt->close();
echo json_encode((bool) $row['item_exists']);