PHP foreach数组冗余


PHP foreach array redundant

这里的foreach数组是多余的。我遇到的问题是,如果(empty($theone['bans']))检查数组是否不在那里,然后继续。然后,如果数组存在,foreach($theone['bans']为$ban)和代码在数组为空的情况下是相同的。我怎样才能缩短这个?

<?php
foreach ($finder['zigzag'] as $zigzag)
{
    foreach ($zigzag as $theone)
    {  
        if(empty($theone['bans']))
        {
            if($theone['total'] >= $theone['limit'])
            {
                echo 'full';
            }
            else
            {
                echo '
                    <form action="" method="post">
                    <input type="submit" name="login" value="" class="input" />
                    <input type="hidden" name="id" value="<?php e($room['id']) ?>" />
                     </form>';
            }
        }
        else
        {
            foreach ($theone['bans'] as $ban)
            {
                if ($finder['profile']['ip'] == $ban['ip'])
                {
                    echo 'Banned user';
                }
                elseif ($theone['total'] >= $theone['limit'])
                {
                    echo 'full';
                }
                else
                {
                    echo '
                    <form action="" method="post">
                    <input type="submit" name="login" value="" class="input" />
                    <input type="hidden" name="id" value="<?php e($room['id']) ?>" />
                     </form>';
                }
            }
        }
    }
}
<?php
foreach ($finder['zigzag'] as $zigzag){
    foreach ($zigzag as $theone){  
        if(isset($theone['bans'])){
            foreach ($theone['bans'] as $ban){
                if ($finder['profile']['ip'] == $ban['ip']){
                    echo 'Banned user';}}}
        else{
            if ($theone['total'] >= $theone['limit']){
                echo 'full';}
            else{
                echo '
                    <form action="" method="post">
                    <input type="submit" name="login" value="" class="input" />
                    <input type="hidden" name="id" value="'.$room['id'].'" />
                    </form>';}}}}
?>

这将检查数组是否已设置。。。

if(isset($theone['bans']))

根据你的数组是如何定义的,你可能需要尝试类似的东西

 if($theone['bans']!='')