在Array中搜索特定值

I have an issue with an array being returned from an API request which i want to search for a specific value and perform a certain operation for but i have been unsucessful in making it work. I have used array_search() function and done several things based on reading similar questions here and online but still no luck. Anyone know what i am doing wrong?

$responses = explode("
", file_get_contents($url));
print_r($responses);

print_r($responses) displays:

Array
(
[0] => destination_msisdn=233887
[1] => country=
[2] => countryid=
[3] => operator=
[4] => operatorid=
[5] => authentication_key=XXXXXX
[6] => error_code=101
[7] => error_txt=Destination MSISDN out of range
)

and this is what i currently have in my code for array search

if(array_search("error_code=101", $responses)){
   echo "Incorrect!";
 }

The result i get from:

   print_r(file_get_contents($url));

is

 destination_msisdn=23345678 country= countryid= operator= operatorid= authentication_key=XXXXX error_code=101 error_txt=Destination MSISDN out of range

Please I am not trying to explode any array value I am trying to search for a string in the array and perform an operation as per my if statement.

Thanks

As we found out in the comments your value error_code=101 is 30 characters long and probably has some spaces at the end, so that's why it doesn't match.

Now you either can remove these spaces when you explode it into an array, e.g.

$responses = preg_split("/\s*
\s*/", file_get_contents($url));

Or you remove them for each element, e.g.

$responses = array_map("trim", $responses);

Also I would recommend you to check for:

array_search("error_code=101", $responses) !== FALSE

Since the key of the value also could be 0, which would result in not entering the if statement.

starting from the fact your code works for me.

Can you try instead exploding the array, searching on the string like this?

if(strpos(file_get_contents($url),"error_code=101")  !== FALSE)
    echo "Incorrect!";

[edited]