我有這個php函數,我創建的基本上是一個switch語句。對於每種情況,$ team_image變量都被保存爲一個不同的值。它看起來有點像這樣:PHP函數不會保存變量
function teamImage($team)
{
switch($team)
{
case "Baltimore Orioles":
$team_image = "orioles";
case "New York Yankees":
$team_image = "yankees";
case "Toronto Blue Jays":
$team_image = "bluejays";
你明白了。但是,當我調用函數並嘗試在我的代碼的其他部分使用$ team_image變量時,它不起作用,因爲顯然變量仍未定義。有什麼想法嗎?
感謝,
蘭斯
沒有足夠的信息來充分回答這個問題。請發佈你打算如何使用'$ team_image'變量。 – 2011-05-01 19:15:21
雖然這似乎不會影響您的問題,但請記住[break語句](http://php.net/break/),如果您需要它,看起來您會像。 – waiwai933 2011-05-01 19:18:24
我不同意沒有足夠的信息來回答問題。我清楚問題出在哪裏(由於缺乏範圍意識)。 – Hammerite 2011-05-01 19:22:02