2016-02-29 53 views
-2

我試圖讓我基本上進入季節如冬季或春季,然後裏顯示在那個賽季在上case.I幾個月我目前得到錯誤(T_CONSTANT_ENCAPSED_STRING)工作PROGRAMM PHP和我不知道從哪裏去這裏。任何幫助謝謝我怎樣才能得到呼應季月

<?php 
if ($_SERVER['REQUEST_METHOD'] === 'POST') { 
//THE ARRAYS 
$seasons = array('winter','spring','summer','autumn'); 

//MAKE THE CHARACTERS LOWER CASE OR HIGER CASE 
$season = (isset($_POST['season']) && $_POST['season'] != "") ?   strtolower($_POST['season']) : ''; 

//in_array — Checks if a value exists in an array 
if($season && in_array($season, $seasons)){       
$months = array(); 
//keyvalue table 
$month_name = array(
1 => "January", 
2 => "February", 
3 => "March", 
4 => "April", 
5 => "May", 
6 => "June", 
7 => "July", 
8 => "Auguest", 
9 => "September", 
10 => "October", 
11 => "November",) 

//keyvalue table connected with seasons 
'winter' => array(1,2,11,12), 
'spring' => array(3,4), 
'summer' => array(5,6,7), 
'autumn' => array(8,9,10), 

if $season=> winter echo 1,2,11,12; 

} 
}else{ 
echo "Invalid season entered"; 
} 
+0

在'「November」後面用分號關閉'$ month_name'行)'和分號而不是逗號在結尾季節數組行 – fusion3k

+1

您的腳本中存在太多錯誤(「'winter'=> array ','$ season => winter' ...)。我想你必須先看看[php基礎知識](http://php.net/manual/en/langref.php),然後再繼續。 – fusion3k

回答

0

更改$month_names聲明。

$month_name = array(
    1 => "January", 
    2 => "February", 
    3 => "March", 
    4 => "April", 
    5 => "May", 
    6 => "June", 
    7 => "July", 
    8 => "Auguest", 
    9 => "September", 
    10 => "October", 
    11 => "November", 
); 

您錯過了分號。最後的逗號是可選的,有些人喜歡留下懸殊的逗號,因爲在複製行以將元素添加到數組時更容易。懸掛分號是有效的語法,它只是被忽略。該代碼更具可讀性並帶有縮進值,並在新行上關閉);

您也有其他語法錯誤,所以我想了解更多的PHP的基礎知識,並考慮語法高亮的編輯器。