所以我有 2 个下拉列表,我需要从中选择一年。然后我需要显示选择的年份和那一年的人口数量。例如:
1800 年:人口:3,929,214
1900 年:人口:76,212,168
人口增加:72,282,954。
所以这是我到目前为止的代码:
<html>
<head>
<meta charset="UTF-8">
<title>Calculator</title>
</head>
<body>
<h1>Population Change Calculator</h1>
<?php
$population=[3929214,5236631,7239881,9638453,12866020,17069453,23191876,31443321];
$year=(range(1790, 1860, 10));
$array= array_combine($year, $population);
?>
<form method="post">
<p><label for="year1">Year 1:</label>
<select name="year1">
<option value=""></option>
<?php
foreach ($array as $year1=>$population){ ?>
<option value="<?php echo $year1; ?>"><?php echo $year1; ?></option>
<?php }
?>
</select>
</p>
<p>
<label for="year2">Year 2:</label>
<select name="year2">
<option value=""></option>
<?php
foreach ($array as $year2=>$population){ ?>
<option value="<?php echo $year2; ?>"><?php echo $year2; ?></option>
<?php }
?>
</select>
</p>
<input type="submit" name="submit" value="Submit">
<br>
</form>
<?php
$ini_set = ini_set('display_errors', 1);
error_reporting(E_ALL);
$empty=true;
if(isset($_POST['submit'])){
if(empty($_POST['year1'])){
$empty=FALSE;
print "<p>Please choose Year 1.</p>";
}
if(empty($_POST['year2'])){
$empty=false;
print "<p>Please choose Year 2.</p>";
}
}
我不知道如何打印所选年份和那一年的人口。
我是 PHP 新手,在此先感谢您。