我需要根据用户是否下载该文件,在文件名旁边生成一个链接。
所以在这里,$done
包含用户下载的文件的id
。它来自一个数据库。
我的问题是,如何为$done
分配多个值,然后运行检查?那么$done
将是1, 3, 5
,然后在while循环中运行这些值?在这种情况下,观看者将收到ids
1, 3, 5
<?php
$i = 1;
$done = 5;//How can I assign multiple values to done and then run the check?
while ($i <= 10) {
echo $i;
echo ($done == $i ? ' You\'ve already downloaded this <br>' : ' You have not downloaded this <br>');
$i++;
}
?>
答案 0 :(得分:3)
您可以将数组值用于$ done
e.g。
$done = array(1,3,5);
//如何为完成分配多个值,然后运行检查?
更正代码:
<?php
$i = 1;
$done = array(1,3,5);//How can I assign multiple values to done and then run the check?
while ($i <= 10) {
echo $i;
if(in_array($i,$done)
echo ' You\'ve already downloaded this <br>';
else
echo ' You have not downloaded this <br>';
$i++;
}