0
<?php
include('database.class.php');
$sql = new Database(NULL);

$ids = $sql->select('*', '`ids` ORDER BY `UserId` ASC', NULL, NULL, NULL, true, true);
$dump = array();
foreach ($ids as $index as $id)
        $dump[] = $id['UserId'].' | REGLINK - http://xat.com/web_gear/chat/register.php?UserId='.$id['UserId'].'&k2='.$id['k2'].'&mode=1';
$DumpFile = 'ids.txt';

if(file_exists($DumpFile)) {
        unlink($DumpFile);
}
file_put_contents($DumpFile, implode("\r\n", $dump));
die(count($dump).' ids were dumped into the list.'."\n");
?>

我已经检查并重试了很多东西,我只是不明白出了什么问题。

4

4 回答 4

13
foreach ($ids as $index as $id)

应该:

foreach ($ids as $index => $id)
于 2013-09-21T06:01:27.663 回答
2

这是错误的:

foreach ($ids as $index as $id)

这不是正确的语法,你没有$index在任何地方使用。只需使用这个:

foreach ($ids as $id)

请参阅有关 foreach 的手册页

于 2013-09-21T06:01:35.647 回答
0

foreach错了。像这样试试。Key -该操作符用来表示的值对=>

<?php
include('database.class.php');
$sql = new Database(NULL);

$ids = $sql->select('*', '`ids` ORDER BY `UserId` ASC', NULL, NULL, NULL, true, true);
$dump = array();
foreach ($ids as $index=>$id)
        $dump[] = $id['UserId'].' | REGLINK - http://xat.com/web_gear/chat/register.php?UserId='.$id['UserId'].'&k2='.$id['k2'].'&mode=1';
$DumpFile = 'ids.txt';

if(file_exists($DumpFile)) {
    unlink($DumpFile);
}
file_put_contents($DumpFile, implode("\r\n", $dump));
die(count($dump).' ids were dumped into the list.'."\n");
?>
于 2013-09-21T06:01:46.670 回答
0

正确的代码

<?php
include('database.class.php');
$sql = new Database(NULL);

$ids = $sql->select('*', '`ids` ORDER BY `UserId` ASC', NULL, NULL, NULL, true, true);
$dump = array();
foreach ($ids as $index => $id)
        $dump[] = $id['UserId'].' | REGLINK - http://xat.com/web_gear/chat/register.php?UserId='.$id['UserId'].'&k2='.$id['k2'].'&mode=1';
$DumpFile = 'ids.txt';

if(file_exists($DumpFile)) {
        unlink($DumpFile);
}
file_put_contents($DumpFile, implode("\r\n", $dump));
die(count($dump).' ids were dumped into the list.'."\n");
?>
于 2013-09-21T06:02:23.950 回答