PHP数组没有保存最后两个元素


PHP array is not saving two last elements

我试图从一个数组复制到另一个,但只有唯一的值。我使用循环,当我调试所有10蓝色显示,但循环后,最后2个值消失了。

我在"for循环"期间调试每个数组元素,看起来很好,因为我看到了所有10个元素。问题开始于for循环之后。例如,如果我想打印第9个元素,它不会打印它,也就是说,它显示为空。

有什么问题吗?

p。S>我试过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>

我想

if(!in_array($isbn_array[$i],$isbn_unique ))
{
    $isbn_unique[$i] = $isbn_array[$i];
    echo $isbn_unique[$i]."  ---- ";
}

应为

if(!in_array($isbn_array[$i],$isbn_unique ))
{
    $isbn_unique[] = $isbn_array[$i];
    echo $isbn_array[$i]."  ---- ";
}

我认为你在$isbn_array中有重复的值,所以它的跳过键已经在数组中,因此$isbn_unique的大小是不同的,然后是$isbn_array。试着调试一下