我怎样才能使这个代码工作?泰!

$site = '1'

    $mysites = array('1', '2', '3', '4', '5', '6');
            foreach($mysites as $mysite)
            {
            echo $mysites;  **but not the site with value 1**
            }

最佳答案

一个简单的if就足够了:

$site = '1';

$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite)
{
    if ( $mysite !== '1' )
    {
        echo $mysite;
    }
}

或者如果不检查$site变量:
$site = '1';

$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite)
{
    if ( $mysite !== $site )
    {
        echo $mysite;
    }
}

08-27 04:16