PHP 数组复制


PHP Arrays duplicating?

我正在尝试编写 cron 作业,因此如果数据库中的代码未使用且较旧,则 72 小时,它会删除数据库中的行。

然而,我遇到的问题是,当我尝试连续获取数组数据时,我可以运行"If 语句",然后运行 drop 命令,在打印数组时,我得到重复项,如下所示

33520891520891do not usedo not use----aaron hattonaaron hattonSunday 8th of September 2013 12:46:20 PMSunday 8th of September 2013 12:46:20 PMUnusedUnused--

我的代码如下

// Set variable for the time
$timenow = date('l jS 'of F Y h:i:s A');
    // Start Expired password check and drop function
    function cronexec_expired ($timenow) {
        include('../../config.php');
        // Open up a new MySQLi connection to the MySQL database
        mysql_connect($dbHost, $dbUsername, $dbPassword);
        mysql_select_db($dbTable);
        // Query to check the status of the code input
        $expiry_check = "SELECT * FROM code_log WHERE status='Unused'";
        // Run the query
        $expiry_checkexec = mysql_query($expiry_check);
        while($expiry_possibles = mysql_fetch_array($expiry_checkexec)) {
            foreach ($expiry_possibles as $expiry_possible) {
                print_r ($expiry_possible);
            };
        }

    }
    // Start Redeemed Password check and drop function
// Execute Functions
cronexec_expired ($timenow);

任何帮助将不胜感激!

编辑

删除"foreach"并运行以下命令时:

print_r ($expiry_possibles);

我得到以下内容

Array ( [0] => 3 [id] => 3 [1] => 520891 [code] => 520891 [2] => do not use [refid] => do not use [3] => - [hostname] => - [4] => - [userip] => - [5] => aaron hatton [creater] => aaron hatton [6] => Sunday 8th of September 2013 12:46:20 PM [timecreated] => Sunday 8th of September 2013 12:46:20 PM [7] => Unused [status] => Unused [8] => - [timeredeemed] => - )

我做错了什么吗?

如果你的意思是数组输出中的数字索引。 使用 mysql_fetch_assoc() 而不是 mysql_fetch_array()

mysql_fetch_array() 本质上返回两个数组,一个带有数字索引,一个具有关联字符串索引。