我希望能够使用函数向名为播放列表的数组添加新值(这是强制性的)。但是每次我输入另一个值时,它都会替换旧值,而不仅仅是添加到数组的末尾。怎么了?
<?php
$playlist = array("Be more.mp3", "Drift Away.mp3", "Panda Sneeze.mp3");
function add_songs_playlist() {
global $playlist;
?>
<form method = "post">
<input type = "text" name = "name1"/>
<input type = "submit" name = "submit1"/>
</form>
<?php
if (isset($_POST['submit1'])) {
$newsong = $_POST['name1'];
array_push($playlist, $newsong);
}
}
add_songs_playlist();
foreach ($playlist as $value) {
echo $value."<br>";
}