基本的な配列の処理ですが、
1-12の値が連想配列になっているものを、通常の配列として考え直し、同じ出力を行いたいです。ご教授お願いいたします。
php
1<!doctype html> 2<html> 3<head> 4<meta charset="UTF-8"> 5<title>sample</title> 6</head> 7<?php 8for ($i = 1; $i <= 12; $i++) { 9 $option_month .= '<option value="' . $i . '">' . $i . '月</option>' . "\n"; 10} 11?> 12<form action="" method="post"> 13<select name="month"> 14<?php echo $option_month?> 15</select> 16<input type="submit" name="btn" value="送信"> 17</form> 18<body> 19<?php 20//季節の配列をつくる 21$array_month['1'] = '冬'; 22$array_month['2'] = '冬'; 23$array_month['3'] = '春'; 24$array_month['4'] = '春'; 25$array_month['5'] = '春'; 26$array_month['6'] = '夏'; 27$array_month['7'] = '夏'; 28$array_month['8'] = '夏'; 29$array_month['9'] = '秋'; 30$array_month['10'] = '秋'; 31$array_month['11'] = '秋'; 32$array_month['12'] = '冬'; 33if (isset($_POST['btn'])) { 34 $month = $_POST['month']; 35 echo $month . '月は' . $array_month[$month] . 'です。' . "\n"; 36} 37?> 38</body> 39</html>
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/06 04:03
2017/04/06 04:12