我怎样才能回应季节月

时间:2016-02-29 17:28:41

标签: php

我试图开始工作的程序基本上我进入季节,例如冬季或春季,然后它显示那个季节的月份大写。我目前收到错误(T_CONSTANT_ENCAPSED_STRING)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";
}

1 个答案:

答案 0 :(得分: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的基础知识,并考虑使用语法高亮的编辑器。