我有一个问题,我不知道一个foreach()循环来更改每个(x)结果数量的输出。foreach()每4个变化输出
这里是我的foreach()代码:
$dir_handle = 'assets/icons/';
foreach(array_diff(scandir($dir_handle), array('.', '..')) as $file) {
$cut = substr($file, -4);
echo '<a href="action.php?do=changeicon&set=' . $cut . '"><img id="preload_header" src="assets/icons/' . $file . '" /></a><br />';
}
我将如何得到它为1-4有同样的结果,但随后5-8有不同的结果,然后再返回到1 4?
你在找什么是[模数运算符](http://www.php.net/manual/en/language.operators .arithmetic.php)。看看这个[示例](http://stackoverflow.com/questions/936242/php-how-do-you-determine-every-nth-iteration-of-a-loop) – gearsdigital
使用增量器,当它达到一个数字可以分为4,做点什么 –