在PHP for 循环中,以
开头function evaluateXPath(page: puppeteer.Page, xpath: string, evalFunc: (value: any, index: number, array: any[]) => any): Promise<any[]> {
return page.waitForXPath(xpath)
.then(() => page.$x(xpath))
.then(handles => page.evaluate((evalFuncStr, ...handles) =>
handles.map(eval(`(${evalFuncStr})`)),
evalFunc.toString(),
...handles))
}
,可以排很长的线。
将其分解成较短部分的最佳方法是什么?
示例:
for (init counter; test counter; increment counter)
答案 0 :(得分:1)
对于特定示例,我认为您使用了错误的循环。您不知道需要迭代多少次,因此,正确的循环将是<path>
。行也不会太长。
while
通常,对于for循环,您几乎应该永远不会获得很长的行,因为它经常与确定的迭代一起使用已知次数。
但是一般来说,为了缩短$currentLine = fgets($fileToAnalyse);
while(!preg_match("^0 @Individual ", $currentLine)) {
// code...
$currentLine = fgets($fileToAnalyse);
}
循环,您可以做一些奇怪的事情,例如将变量的定义导出到第一行之外(我不推荐),例如:< / p>
for