我想從函數內部訪問數組數據,但不斷收到錯誤:Undefined varaible:status。任何想法如何糾正?PHP函數中的數組
<?php
$state = 'New York';
function state_values($state){
switch ($state) {
case 'New York':
echo "State is $state";
$status = array("abbr" => "NY", "code" => "03");
return $status;
break;
case 'California':
echo "State is $state";
$status = array("abbr" => "CA", "code" => "06");
return $status;
break;
case 'Washington':
echo "State is $state";
$status = array("abbr" => "WA", "code" => "05");
return $status;
break;
}
}
# Call the function
state_values($state);
echo $status['abbr'];
echo $status['code'];
?>
-1請甚至不談論全局的人誰顯然不準備聽到的答案不搞亂 – 2010-09-16 13:46:53
我仍然認爲這是一個這個問題的未來讀者的有效點。但我試圖更清楚地表明,我認爲全球方法並不理想。 – 2010-09-16 14:38:56