在PHP中添加字符串不起作用

I'm making a bot that returns Mojang's server status. Here's the code.

$scan = json_decode(file_get_contents("https://status.mojang.com/check"), true);

$errors = array();

if ($scan[0]["minecraft.net"] !== "green") {
    array_push($errors, "Minecraft is down: ");
}

if ($scan[1]["session.minecraft.net"] !== "green" || $scan[6]["sessionserver.minecraft.net"] !== "green") {
    array_push($errors, "All server sessions are down. ");
}

if ($scan[2]["account.minecraft.net"] !== "green") {
    array_push($errors, "Account services are down. ");
}

if ($scan[3]["auth.minecraft.net"] !== "green" || $scan[5]["authserver.minecraft.net"] !== "green") {
    array_push($errors, "Authentication servers are down. ");
}

if ($scan[4]["skins.minecraft.net"] !== "green") {
    array_push($errors, "Skin servers are down. ");
}

$message = "Sometimes it's Mojang... ";

if (sizeof($errors) !== 0) {
    foreach ($errors as $i) {
        $message .= $errors[$i];
    }
} else {
    $message .= "but today, it seems like all of Mojang's servers are working fine!";
}

echo $message;

Whenever I execute this in my terminal, it outputs "Sometimes it's Mojang... ", and that's it. There's nothing else. Either way, if the if is true or false, it will add something to the string, so it should be printing more than that, but it isn't. Any help would be appreciated, and sorry if this is an easy fix.

Thank you!

Two ways

You are passing the value as keys then the value is not found

use key instead of val

 foreach ($errors as $i => $val) {
    $message .= $errors[$i];
 }

Or use direct value

 foreach ($errors as $i) {
    $message .= $i;
  }

The problem is not with your if statement, you are trying to access variables to do not exist. For example, account.minecraft.net should be account.mojang.com. PHP should have outputted errors, but they must be suppressed on your setup. Here is a fixed file, using the correct keys:

$scan = json_decode(file_get_contents("https://status.mojang.com/check"), true);
$errors = array();

if ($scan[0]["minecraft.net"] !== "green") {
    array_push($errors, "Minecraft is down: ");
}

if ($scan[1]["session.minecraft.net"] !== "green" || $scan[6]["sessionserver.mojang.com"] !== "green") {
    array_push($errors, "All server sessions are down. ");
}

if ($scan[2]["account.mojang.com"] !== "green") {
    array_push($errors, "Account services are down. ");
}

if ($scan[3]["auth.mojang.com"] !== "green" || $scan[5]["authserver.mojang.com"] !== "green") {
    array_push($errors, "Authentication servers are down. ");
}

if ($scan[4]["skins.minecraft.net"] !== "green") {
    array_push($errors, "Skin servers are down. ");
}

$message = "Sometimes it's Mojang... ";

if (sizeof($errors) !== 0) {
    foreach ($errors as $i) {
        $message .= $errors[$i];
    }
} else {
    $message .= "but today, it seems like all of Mojang's servers are working fine!";
}

echo $message;

Running the updated file on my local server yields the following result: Sometimes it's Mojang... but today, it seems like all of Mojang's servers are working fine!.