acmumph Posted August 5, 2011 Share Posted August 5, 2011 So I'm trying to get a variable assigned by stepping through an array using the following code. $american=array("ABC","Beefmaster","Braford","Brahman","Brahmousin","Brangus","OARB","Red Brahman","Red Brangus","Santa Gertrudis","Simbrah","Star5"); $british=array("Angus","Hereford","Polled Hereford","Lowline Angus","Red Angus","Shorthorn"); $exotic=array("AOB","Braunvieh","Charolais","Chi","Limousin","Maine Anjou","ORB","Simmental"); if ($species==$american[]) { $division="American"; } else if ($species==$british[]){ $division="British"; } else if ($species==$exotic[]){ $division="Exotic"; } Appreciate your time Quote Link to comment https://forums.phpfreaks.com/topic/243895-array-solution/ Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 use in_array $american=array("ABC","Beefmaster","Braford","Brahman","Brahmousin","Brangus","OARB","Red Brahman","Red Brangus","Santa Gertrudis","Simbrah","Star5"); $british=array("Angus","Hereford","Polled Hereford","Lowline Angus","Red Angus","Shorthorn"); $exotic=array("AOB","Braunvieh","Charolais","Chi","Limousin","Maine Anjou","ORB","Simmental"); if (in_array($species,$american)) { $division="American"; } else if (in_array($species,$british)) { $division="British"; } else if (in_array($species,$exotic)) { $division="Exotic"; } Quote Link to comment https://forums.phpfreaks.com/topic/243895-array-solution/#findComment-1252372 Share on other sites More sharing options...
acmumph Posted August 5, 2011 Author Share Posted August 5, 2011 Awesome...worked like a champ Quote Link to comment https://forums.phpfreaks.com/topic/243895-array-solution/#findComment-1252580 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 Np.. Quote Link to comment https://forums.phpfreaks.com/topic/243895-array-solution/#findComment-1252755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.