开发者

How to set this cases depends on if rule

if i've the following

$x = "go";
$y = "went";
$z "gone";

and i need to set title where title will be

$title = $x;              //only if "y" empty no care about "z" if empty or not
$title = $x . " - " . $y; // if "y" not empty and "z" is empty
$title = $y . " - " . $z; // if "z" not empty and "y" not empty

this is my try but field and/or looks so permeative (i'm noob)

$empty = ""; // i've creaty empty example
$x = "go";
$y = "went";
$z "gone";

if ($y==$empty) {
$title = $x; // output should be go

} else if($y!=$empty && $z==$empty) {
$title = $x . " - " . $y;  // o开发者_JS百科utput should be go - went

} else if($y!=$empty && $z!=$empty) {
$title = $y . " - " . $z;  // output should be went - gone

} else {
$title = $x;  // output should be go
}

do anyone have better suggestion ! thanks a lot


$title = empty($y) ? $x : (empty($z) ? $x."-".$y : $y."-".$z);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜