【发布时间】:2020-04-20 08:08:57
【问题描述】:
我对 if 条件中语句的含义及其用途有疑问。我在下面发布了完整的 PHP 代码。这是我目前正在研究的另一个人的代码,我的问题是关于特定的代码行(请参阅我的问题的下一段)。
<?php
$dir = '../assets/videos/';
if(is_dir($dir)) {
$filesread = array();
$dh = opendir($dir);
print_r($filesread);
while(($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..') {
//returns all file names wihout extension
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file);
if($filesread[$withoutExt] !== true) {
$hasSQL = false;
foreach($films as $f) {
if($f['file_name'] == $withoutExt) {
echo '
<div class="row">
<div class="col-xs-8">
<a href="'.$dir.$f['file_name'].'.mp4" target="_blank">'.$withoutExt.'</a>
</div>
<div class="col-xs-4">
[<a class="edit" id="'.$f['filmID'].'" data-title="'.$f['title'].'" data-category="'.$f['categoryID'].'" data-file-name="'.$f['file_name'].'" data-desc="'.$f['description'].'">Edit</a>] [<a href="films.php?remove='.$f['filmID'].'">Remove</a>]
</div>
</div><br />';
$hasSQL = true;
print_r($withoutExt);
}
}
if($hasSQL == false) {
echo '
<div class="row">
<div class="col-xs-8">
<a href="'.$dir.$withoutExt.'.jpg" target="_blank">'.$withoutExt.'</a>: <strong>DOES NOT HAVE DATA</strong>
</div>
<div class="col-xs-4">
[<a class="add" data-file-name="'.$withoutExt.'"">Add Data</a>] [<a href="films.php?remove='.urlencode($withoutExt).'">Remove</a>]
</div>
</div><br />';
}
$filesread[$withoutExt] = true;
}
}
}
} else {
echo 'Invalid directory';
}
?>
在这个 php 代码中,我不太确定 if($filesread[$withoutExt] !== true) 语句是什么意思。
if($filesread[$withoutExt] !== true) {//code to be excute}
我不知道$filesread[$withoutExt] 是什么。我所知道的是$filesread = array(); 和$withoutExt 是没有扩展名的文件名。我的猜测是程序员试图使用$withoutExt 作为从$filesread 数组中获取值的键,但$filesread 是一个空数组。他如何从空数组中获取值?有谁了解$filesread[$withoutExt] 的含义,以及这个 if 语句的目的?非常感谢!
【问题讨论】:
标签: php arrays file directory conditional-statements