0

我需要根据用户是否下载该文件来生成文件名旁边的链接。

所以在这里,$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++;
}
?>
4

1 回答 1

3

您可以使用数组值来 $done

例如

$done = array(1,3,5);//如何给done分配多个值然后运行检查?

更正的代码:

<?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++;
}
于 2013-05-30T04:43:04.540 回答