PHP loop checking existence of a string in an array then outputting a boolean

rootpauttneam

New Member
Fairly rubbish with PHP, this is a continuation on from my last question.I have a list of user agents inside an array, and I want an output to be true if the user agent matches one listed inside the array.This is what I have for a single user agent:\[code\] <?php function mediaType(){ $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone"); $var = 0; if ($browser !== false) { $var = 1; } return $var; } ?>\[/code\]I want something like this:\[code\]<?phpfunction mediaType(){ $userAgents = array("iPhone", "Chrome"); $browser = $_SERVER['HTTP_USER_AGENT']; $var = 0; if (in_array($browser, $userAgents)) { $var = 1; } return $var; }?>\[/code\]I guess a while loop would be a good option, but I am clueless.
 
Back
Top