Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 参数太少的vprintf()_Php - Fatal编程技术网

Php 参数太少的vprintf()

Php 参数太少的vprintf(),php,Php,我有这个php错误,但是脚本可以工作。我认为第一个vprintf()是正确的,只有第二个vprintf()有这个错误 vprintf(): Too few arguments function CreateLangTable($csvFile, $startRow, $endRow, $number) { global $lang_code1, $lang_code2, $vocabulary_group, $teilurl; if ($endRow < $start

我有这个php错误,但是脚本可以工作。我认为第一个
vprintf()
是正确的,只有第二个
vprintf()
有这个错误

vprintf(): Too few arguments 

function CreateLangTable($csvFile, $startRow, $endRow, $number) {
    global $lang_code1, $lang_code2, $vocabulary_group, $teilurl;

    if ($endRow < $startRow) {
        return;
    }
    echo ' 
  <a id="' . $vocabulary_group[$teilurl[4]][$number] . '"></a>      
  <table class="table-vocabulary">                           
    <thead>';
    $csvFile->seek($startRow);

    vprintf('
        <tr>
          <th><div data-text="%1$s" data-lang="' . $lang_code1 . '" class="trigger_play"> %1$s</div></th> 
          <th><div data-text="%2$s" data-lang="' . $lang_code2 . '" class="trigger_play"> %2$s</div></th>
        </tr>
    </thead>
    <tbody>', $csvFile->current());

    while ($csvFile->key() <= $endRow) {
        $csvFile->next();

    vprintf('   
        <tr>
          <td><div data-text="%1$s" data-lang="' . $lang_code1 . '" class="trigger_play"> %1$s</div></td> 
          <td><div data-text="%2$s" data-lang="' . $lang_code2 . '" class="trigger_play"> %2$s</div></td>
        </tr>', $csvFile->current());
    }

    echo '
    </tbody>
  </table>' . "\n";
}
我使用此代码生成了正确的表:

CreateLangTable($file, 0, 4, 0);
CreateLangTable($file, 6, 9, 1);

如果我将4更改为3,将9更改为8,错误将消失,但原因是什么?

这里的问题是,在获得当前值之前,在
$csvFile
中移动指针

所以,当指针指向最后一个元素时,可以使用
next
将其向前移动。那么现在的元素是什么呢?我认为它是空的

您只需在
vsprintf

或者可以使用
valid
检查当前值是否为有效值。

当您到达
$csvFile
的最后一个元素时,执行
下一步
获取什么?@u\mulder我现在发布了整个函数。似乎@u\mulder建议您检查
$csvFile->current()中的内容
到达
$endRow
后。您可以使用XDebug来找到答案,或者只需在循环中的
$csvFile->next()
之后添加一个
var\u转储($csvFile->current())
,以检查每一行的值。通过这种方式,您可以确认是否确实有一个数组,其中所有行至少有两个值。我将添加一个示例。谢谢。我在
vsprintf
之后使用了
next
,错误消失了,因此我不必更改第二个参数的值。当我在
vsprintf
之后使用
next
时,脚本将生成第一行值的两倍,首先作为
的值,然后像
中的其他值一样。如果我放置
$csvFile->next(),它应该只在
中显示它之前,当
循环时,我会得到一个无限循环来打印第一个
CreateLangTable($file, 0, 4, 0);
CreateLangTable($file, 6, 9, 1);