运行IF直到其为true,然后转到Else PHP


Run IF till its true then goto Else PHP

我正在创建一个for循环,我希望条件如下:

if(get_field('top', $post->ID) == "Yes") 
{ 
    $HeadClass = "first";
    $priority = 1;
} 
else 
{ 
    $priority = 2;
    $HeadClass = "second"; 
}
switch($HeadClass)
{
    case "first":
        $ImgHolderStyle = 'style="position:relative;height:300px;background:#212121;"';
        $ImgStyle = 'style="position:absolute;left:192px;" src="images/img1.jpg" width="300" height="300"';
        $TitleBox = 'title-box';
        $TitleBg = 'bg';
        $NamedClass= '';
        $TitleNewsClass= '';
        $PostTitleClass = '';
        $View = true;
        $ExtraClass = "888";
        break;
    case "second":
        $ImgHolderStyle = 'style="width:235px;height:276px;"';
        $ImgStyle = 'width="240" height="276"';
        $TitleBox = '';
        $TitleBg = '';
        $View = false;
        $ExtraClass = "";
        break;
}

在上面的代码中,我希望IF条件一直运行到它为true,然后转到else。我的意思是,根据$HeadClass = "first";的出现,只有当它为false时,才运行到ELSE

我得到的输出id:

<div class="first"></div>
<div class="second"></div>
<div class="second"></div>
<div class="first"></div>

我想成为的是:

<div class="first"></div>
<div class="first"></div>
<div class="second"></div>
<div class="second"></div>

$priority = 1;
while( .... ) {
    if ( 1===$priority && 'Yes'!=get_field('top', $post->ID) ) {
        $priority = 2;
    }
    switch($priority) {
        case 1:
            $HeadClass = 'first';
            $ImgHolderStyle = 'style="position:relative;height:300px;background:#212121;"';
            // ...
            break;
        case 2:
            $HeadClass = "second";
            $ImgHolderStyle = 'style="width:235px;height:276px;"';
            // ...
            break;
    }
}