[英]Run IF till its true then goto Else PHP
I am creating a for loop where i want condition to be like this: 我正在创建一个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;
}
in above code i want IF
condition to be run till its true, then it go to else. 在上面的代码中,我希望将
IF
条件运行到其为真,然后转到其他条件。 I mean according to the occurance of $HeadClass = "first";
我的意思是根据
$HeadClass = "first";
run only if, when this get false then goto to ELSE
. 仅当此条件为假时运行,然后转到
ELSE
。
What output i am getting id: 我得到的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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.