所以我有这个代码根据文件是否存在来分配不同的变量:
$progress_file_path = './data/progress.txt';
if (file_exists($progress_file_path) && count($scanned) > 0) {
$scanned = file($progress_file_path);
$last = end($scanned);
$end = $limit + count($scanned);
}
else {
$last = 'unset';
$end = $limit;
}
但是我需要做更多的事情,我需要确保文件中包含内容。我按照这样的条件进行检查:
if (file_exists($progress_file_path) && count(file($scanned)) > 0)
因为尚未定义$scanned
变量。所以理想的解决方案是如果我可以突破if语句,并跳转到条件的else
部分。
这样的事情:
$progress_file_path = './data/progress.txt';
if (file_exists($progress_file_path)) {
$scanned = file($progress_file_path);
if (count($scanned) > 0) { break; }
$last = end($scanned);
$end = $limit + count($scanned);
}I
else {
$last = 'unset';
$end = $limit;
}
但是这不起作用,你不能破坏或继续if语句。我想也许可以使用goto
跳转到有条件的else
部分,但我怀疑它是否会起作用。有没有办法像这样跳转到条件的其他部分?
答案 0 :(得分:1)
您可以尝试在一个if语句中检查两个条件,以至少有一个像这样的
timer1.Enabled = false;
MessageBox.Show();
timer1.Enabled = true;
答案 1 :(得分:1)
精炼Anant答案
$progress_file_path = './data/progress.txt';
$last = 'unset';
$end = $limit;
if (file_exists($progress_file_path)) {
$scanned = file($progress_file_path);
if (count($scanned) < 0) {
$last = end($scanned);
$end = $limit + count($scanned);
}
}