code ส่วนบน
<style>
table, th, td {border: 1px solid black;border-collapse: collapse;}
th, td {padding: 5px;}
table {margin: 0 auto;}
form {margin: 0 auto;text-align:center;}
</style>
</head>
<body>
<form action="" method="post">
<label for="gender">เพศ:</label>
<select id="gender" name="gender">
<option value="male">ชาย</option>
<option value="female">หญิง</option>
</select>
<label for="age">อายุ:</label>
<select id="age" name="age">
<option value="age1">18-34</option>
<option value="age2">35-44</option>
<option value="age3">45-54</option>
<option value="age4">55-64</option>
<option value="age5">65+</option>
</select>
<br><br>
<input type="submit" name="submit" value="คำนวณ แผนประกัน" class="button"/>
</form>
<br>
<?php
if(isset($_POST['submit'])){
$gender = $_POST['gender'];
$age = $_POST['age'];
$hc = array(1000, 2000, 2500, 3000, 4000, 5000); //ชดเชยรายได้ = hc
$life = array(100000, 100000, 500000, 750000, 1000000, 3000000); //ทุนประกันชีวิต
$lifep = array(10000, 10000, 50000, 75000, 100000, 300000); // เบี้ยประกันชีวิต
$costs = array(
"male" => array(
"age1" => array(100, 200, 250, 300, 400, 500),
"age2" => array(110, 220, 275, 330, 440, 550),
"age3" => array(130, 260, 325, 390, 520, 650),
"age4" => array(150, 300, 375, 450, 520, 750),
"age5" => array(200, 400, 500, 600, 800, 1000)
),
"female" => array(
"age1" => array(20, 40, 50, 60, 80, 100),
"age2" => array(24, 48, 60, 72, 96, 120),
"age3" => array(40, 80, 100, 120, 160, 200),
"age4" => array(150, 300, 375, 450, 520, 750),
"age5" => array(200, 400, 500, 600, 800, 1000)
)
);
$total_cost = $costs[$gender][$age];