我目前正在玩数组,这是我到目前为止所做的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>13.15</title>
</head>
<body>
<form method="post">
fruit: <input type="text" name="fruit"><br><br>
<input type="submit" name="add" value="add"><br><br>
-------------------------<br><br>
<input type="submit" name="sort" value="sort"> <input type="submit" name="shuffle" value="'shuffle'"><br><br>
-------------------------
<br><br>
</form>
<?php
$fruit = array("Apple", "Mango", "Pear", "Banana");
if(isset($_POST['sort']))
{
sort($fruit);
foreach ($fruit as $key => $val) {
echo "- " . $val . "<br />" . "\n";
}
}
if(isset($_POST['shuffle']))
{
shuffle($fruit);
foreach ($fruit as $key => $val) {
echo "- " . $val . "<br />" . "\n";
}
}
?>
</body>
</html>
将水果添加到阵列的最佳方法是什么?我已经为它创建了按钮和输入字段,但我似乎找不到最适合它的代码