How can i make this code work? TY!
$site = '1'
$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite)
{
echo $mysites; **but not the site with value 1**
}
A simple if will suffice:
$site = '1';
$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite)
{
if ( $mysite !== '1' )
{
echo $mysite;
}
}
or if you wan't to check against the $site variable:
$site = '1';
$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite)
{
if ( $mysite !== $site )
{
echo $mysite;
}
}
$site = '1' isn't valid, $site = '1'; is. Plus, echo $mysites; won't display anything since $mysites is an array. Please, don't copy/paste bad code from the OP question just to be faster to answer.$site = '1'
$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite) {
if ($mysite == $site) { continue; }
// ...your code here...
}
you can do this:
$mysites = array('1', '2', '3', '4', '5', '6');
foreach($mysites as $mysite)
{
if($mysite != 1){
echo $mysite;
}
}