我试图通过一组记录,所有这些记录都有一个“数字”属性。我试图检查是否有3个连续的记录,例如6,7和8.PHP循环检查一组数字是连续的
我想我几乎与下面的代码一样,尽管在最后阶段击中了墙 - 任何帮助将是伟大的!
$nums = array();
while (count($nums <= 3))
{
//run through entries (already in descending order by 'number'
foreach ($entries as $e)
{
//ignore if the number is already in the array, as duplicate numbers may exist
if (in_array($e->number, $num))
continue;
else
{
//store this number in the array
$num[] = $e->number;
}
//here i need to somehow check that the numbers stored are consecutive
}
}
嗨Eineki,条目是降序,你会如何修改你的代码以适应? – pauld78 2010-06-28 22:56:01
@ pauld78只是将+符号还原为 - (我已经修改了函数来做到这一点) – Eineki 2010-06-28 23:02:24