I know how to work with simple arrays, like this:
If you could describe this as a one-on-one script, I'd now like to write a many-on-one script. For example, imagine the following switch:Code:$That = array('usa', 'mex', 'jpn'); $This = array('United States', 'Mexico', 'Japan'); $Text = str_replace($That, $This, $Text);
Now imagine a similar downstream code that's in a loop...Code:switch($Taxon) { case 'Canidae': $Group = 'Carnivores'; break; case 'Felidae': $Group = 'Carnivores'; break; case 'Ursidae': $Group = 'Carnivores'; break; default: break; }
Code:switch($Taxon) { case 'Canidae': $NewValue = 'Diet'; break; case 'Felidae': $NewValue = 'Diet'; break; case 'Ursidae': $NewValue = 'Diet'; break; default: break; }
Rather than list all these values (there will hundreds of values) a second time, I'd like to make it simpler, something like this...
But this code doesn't work. Is there some sort of array I can write that will let me replace an echo value (e.g. $Group) with ANYTHING included in an array? In other words, the switch above would work for any value in my array - Canidae, Felidae or Ursidae.Code:switch($Group) { case '$Carnivores': $NewValue = 'Diet'; break; default: break; }
I hope I explained this right. I was doing this with a database, but that has a few problems of its own, so I want to try it with an array, or whatever works. Thanks.Code:switch($Taxon) { // $Carnivore = an array that includes the values Canidae, Felidae and Ursidae. Thus, $NewValue will = 'Diet' whether a looped value is Canidae, Felidae or Ursidae. case '$Carnivore': $NewValue = 'Diet'; break; default: break; }



Reply With Quote

Bookmarks