使用in_array函数在变量中找不到字符串

I'm trying to search the array $outcome for the string "Destination host unreachable" and it doesn't work.

I'm not sure what I'm doing wrong and was wondering if someone could lend a hand?

   $ip = 192.168.1.30

   $pingresult = exec("ping -n 1 $ip", $outcome, $status);

   if ($status == 0) 
       {                                        
           if(in_array("Destination host unreachable", $outcome))
               {
                   echo "Unreachable";
               }
           else
               {
                   echo "Alive";
               }   
       }

P.S. Please note I'm on a Windows machine so the exit status is different to Linux etc.

you can also try.

if(array_search($outcome, "Destination host unreachable") !== false){
 echo 'not reachable';
}

in_array returns true on exact matches only. So, if there are additional characters on the line (including white space), it won't match. You may wish to loop through the array using preg_match.