duanfei8149 2013-01-07 20:07
浏览 9
已采纳

我的PHP代码有什么问题? [关闭]

I am trying to find lowest of odd numbers in an array.

Here is my code:

$a=array(81,10,6,71,13,61,8,16,0,9,12);
$b=count($a);
for($i=0;$i<$b;$i++)
{
    if($a[$i]/2!=0)
    {
        $flag=0;

        for($j=0;$j<$b;$j++)
        {
            if($a[$j]<=$a[$i] and $a[$j]/2!=0)
            {
                $a[$i]=$a[$j];
                $flag=1;        
            }
        }

        if($flag==1)
        {
            echo('lowest odd number is'.$a[$i]);
        }

        break;
    }

    break;
}

I am not looking for new logic I am just trying to find an error in the above code. Why is it not working?

  • 写回答

1条回答 默认 最新

  • douxunwei8259 2013-01-07 20:09
    关注

    You want mod (%) instead of division (/), as in

    if($a[$i]%2!=0)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?