我正在尝试从一个数组复制到另一个数组,但只有唯一值。我使用 for 循环,当我调试时显示所有 10 个蓝调,但在 for 循环之后,最后 2 个值消失了。
我在“for 循环”期间调试了每个数组元素,看起来很好,因为我看到了所有 10 个元素。问题在 for 循环之后开始。例如,如果我想打印第 9 个元素,它不会打印它,即它显示为 emty。
可能是什么问题?
PS> 我试过 array_unique(),同样的输出,所以不是它。
这是我的代码:
<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE); //to remove annoying notices
include 'connectDB.php';
$queryISBN = mysql_query("SELECT * FROM booksread");
$numrows = mysql_num_rows($queryISBN);
if($numrows!=0)
{
$isbn_array = array();
while($row = mysql_fetch_assoc($queryISBN))
{
$isbn_array[]=$row['ISBN'];
}
$isbn_unique = array();
for ($i=0;$i<count($isbn_array );$i++)
{
if(!in_array($isbn_array[$i],$isbn_unique ))
{
$isbn_unique[$i]=$isbn_array[$i];
echo $isbn_unique[$i]." ---- ";
}
}
}
echo "<h1>Select books you would like to view</h1>";
$submit = $_POST['submit'];
if(isset($_POST['selectedbooks']))
{
$checked = $_POST['selectedbooks'];
}
if($submit)
{
if(!isset($checked))
{
echo "You must check at least one book.";
}
else
{
$_SESSION['checked'] = $checked;
header("location: view_entries_results.php");
}
}
?>
<html>
<body>
<form action="view_entries.php" method="POST">
<table>
<table border="1">
<th>ISBN<th>Title<th>Author<th>Select</th>
<?php
echo "Arr size: ".count($isbn_unique )." </br>";
echo "8: ".$isbn_unique[7]."</br>";
for ($j=0;$j<count($isbn_unique );$j++)
{
$curElement = $isbn_unique[$j];
echo "Cur el: ".$curElement;
$queryBook = mysql_query("SELECT * from book WHERE ISBN='$curElement'");
while ($row = mysql_fetch_assoc($queryBook))
{
$ISBN = $row['ISBN'];
$title = $row['Title'];
$author = $row['Authorname'];
}
?>
<tr>
<td><?php echo $ISBN; ?></td>
<td><?php echo $title; ?></td>
<td><?php echo $author; ?></td>
<td><input type="checkbox" name="selectedbooks[]" value="<?php echo $ISBN; ?>"/>
</tr>
<?php } ?>
</table>
<p><input type="submit" name="submit" value="Add Entry" /></p>
</form>
</body>
</html>