Jump to content

Array solution


acmumph

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/243895-array-solution/
Share on other sites

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";
} 

Link to comment
https://forums.phpfreaks.com/topic/243895-array-solution/#findComment-1252372
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.