【发布时间】:2016-02-16 23:00:21
【问题描述】:
$add = array_splice($fileArr1, $addWhere, 1, $addSong);
我一直在从事一个项目,该项目根据表单中的变量将歌曲名称添加到数组中的特定位置。我真的很困惑,如果这有助于解决我的问题,我可以提供额外的代码。谢谢。
<form method="post" action="addtlogan9573.php">
<p><label for="addSong">Add what song? </label><input type="text" name="addSong" id="addSong" /></p>
<p><label for="addWhere">Add where? </label><input type="text" name="addWhere" id="addWhere" /></p>
这是我的全部代码。
<?php
$fileName = "tunes.txt";
$fileString = file_get_contents($fileName);
$fileArr = explode("|", $fileString);
$fileArr1 = array_values($fileArr);
array_unshift($fileArr1, ' ');
unset($fileArr1[0]);
if (!$_POST) {
?>
<form method="post" action="addtlogan9573.php">
<p><label for="addSong">Add what song? </label><input type="text" name="addSong" id="addSong" /></p>
<p><label for="addWhere">Add where? </label><input type="text" name="addWhere" id="addWhere" /></p>
<input class="MyButton" type="submit" name="submit">
</form>
<?php
}
else {
print "<pre>";
$addSong = $_POST['addSong'];
$addWhere = $_POST['addWhere'];
$add = array_splice($fileArr1, $addWhere, 1, $addSong);
foreach ($add as $key => $val){
print "$key. $val\n";
}
print "</pre>";
$append=implode("|", $fileArr1);
file_put_contents("backups/".microtime("tunes.txt"), $append);
include("inc_navigationtlogan9573.php");
?>
【问题讨论】: