好的,尝试创建一个可以将变量传递给的函数,该函数将在静态当前硬编码的多维数组中搜索其键,并返回与找到的键匹配的数组(如果找到)。
这就是我迄今为止所拥有的。
public function teamTypeMapping($teamType)
{
//we send the keyword football, baseball, other, then we return the array associated with it.
//eg: we send football to this function, it returns an array with nfl, college-football
$mappings = array(
"football" => array('nfl', 'college-football'),
"baseball" => array('mlb', 'college-baseball'),
"basketball" => array('nba', 'college-basketball'),
"hockey" => array('nhl', 'college-hockey'),
);
foreach($mappings as $mapped => $item)
{
if(in_array($teamType, $item)){return $mapped;}
}
return false;
}
我想打电话给它,例如:
teamTypeMapping("football");
Amd 让它返回与键“足球”相关联的数组,我已经尝试了几种方法,每次我出现错误时,也许我错过了一些东西,所以我在这一点上接受一些建议。