php

I am creating a for loop where i want condition to be like this:

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;
}

in above code i want IF condition to be run till its true, then it go to else. I mean according to the occurance of $HeadClass = "first"; run only if, when this get false then goto to ELSE .

What output i am getting id:

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

What i want to be is:

 <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;
    }
}

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question if else true condition to check in PHP the condition of if and else are false and its jump to else directly and my data are true Else statement runs even if the “if” statements are true in PHP if else in php echo (acf true/false condition) PHP if/else issue using true/false if and else both are true in my php codes What is the difference between an if (true)/else (false) and a if(!true) in php? Else If Does Not Run Correctly on PHP if condition is true goto the start of the program PHP agi Goto Queue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM