我正在尝试使用if语句来回显内联样式。但是我只能让我的条件在任何1个数字上返回true,而不是数组,||分开等...
你能解释一下如何制作||版本和数组在我的条件中返回true。
// Works.
$counts = 0 ;
foreach ($posts as $post) : setup_postdata($post); $counts++;
if ($counts == 8) {echo 'counts equals your numbers';}
endforeach;
// This does nothing.
$numbers = array(4,8);
$counts = 0 ;
foreach ($posts as $post) : setup_postdata($post); $counts++;
if ($counts == $numbers) {echo 'counts equals your numbers';}
endforeach;
// Returns true for every iteration.
$counts = 0 ;
foreach ($posts as $post) : setup_postdata($post); $counts++;
if ($counts == 4 || 8) {echo 'counts equals your numbers';}
endforeach;
答案 0 :(得分:1)
||
的语法是:
if ($counts == 4 || $counts == 8) {echo 'counts equals your numbers';}
答案 1 :(得分:0)
使用PHP的内置in_array
函数:
if ( in_array($counts, $numbers) ) {echo 'counts equals your numbers';}