I'm trying to output certain values of this array. It's a months/season array. The user is asked to input a season, and depending on what season they input, I want it to output months in that season.
Here is what I have so far -
$user_input = $_POST ['user_input'];
$month_season = array(
'January' => 'Winter',
'February' => 'Spring',
'March' => 'Spring',
'April' => 'Spring',
'May' => 'Summer',
'June' => 'Summer',
'July' => 'Summer',
'August' => 'Autumn',
'September' => 'Autumn',
'October' => 'Autumn',
'November' => 'Winter',
'December' => 'Winter'
);
$j = 0;
foreach ($month_season as $value) {
if ($month_season[$j] = 'Winter')
{
echo $month_season[$j];
echo "<br>";
$j++;
}
}
For example, i'm just using winter until i get it working, then i will expand the code for all seasons. However, when I input winter in the previous page, the out put is 12 winters. I assume it's just outputting winter for each of the iterations.
Why is this? What should I be doing here to get what I want?
Thanks in advance.
=assignment ;==comparison (Also just to note here: You can't use associative keys as numerical keys)if ($month_season[$j] = 'Winter')should be likeif ($value ==$user_input).print_r($month_season);after your code you will see what you created.