Maison  >  Article  >  développement back-end  >  来看看这个图里面的数字应该怎么算出来?

来看看这个图里面的数字应该怎么算出来?

WBOY
WBOYoriginal
2016-06-23 14:05:211189parcourir



就是这些被红字的数字,每行3个,所有偶数行的数字应该怎么通过数学的方法算出来?
取余的话取的是纵列的数字,怎么样能把红字的偶数行给表达出来?


回复讨论(解决方案)

{wf:if $smarty.section.product.rownum eq 4 or $smarty.section.product.rownum eq 5 or $smarty.section.product.rownum eq 6 or $smarty.section.product.rownum eq 10 or $smarty.section.product.rownum eq 11 or $smarty.section.product.rownum eq 12}要输出的内容{qf:/if}

现在我的写法是这样的,但是明显太不合理了,问下大神怎么写方便

int((n+2)/3) & 1 == 0

其实我要判断的最多也就是4、5、6、7、8、9、16、17、18这九个数字。

for ($n=1;$n     if(($n-1)/3%2 != 0)
        echo $n."\t";
}
//output: 4 5 6 10 11 12 16 17 18

判定行号是否为偶数

for($i=1;$i for($j=1;$j echo $i*3+$j.' ';
}
echo '
';
}

其实我要判断的最多也就是4、5、6、7、8、9、16、17、18这九个数字。
7、8、9不在偶数行啊?!

引用 3 楼 wenfei307 的回复:其实我要判断的最多也就是4、5、6、7、8、9、16、17、18这九个数字。
7、8、9不在偶数行啊?! 打错了,应该是10、11、12

smarty ??
他不是有个 cycle 控制变量吗?为什么不用!
test.php 

include_once("smarty_inc.php"); $arr=array('a','b','c','d','e','f'); $smarty->assign('arr',$arr); $smarty->display("test.tpl"); 
 
test.tpl 
<table width="100px"> {section name=a loop=$arr} <tr bgcolor="{cycle values="#eeeeee,#55eero"}"> <td> {$arr[a]} </td> </tr> {/section} </table>
 

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn