简体   繁体   English

如果在PHP中的其他内部回声

[英]If else inside echo in php

I want to change this code: 我想更改此代码:

echo"
td class='inhoud_c' width='5%'>".$i."</td>
<td class='inhoud' width='25%'><a href='profile.php?x=".$naam."'>".$naam."</td>
<td class='inhoud_c' width='50%'>
<table border='0' cellspacing='0' style='margin: 0px;'>
    <tr>
   <td>
       <img src='".$icon."' alt='' border='0'>
  </td>
     <td>
         ".$land."
    </td>
</tr>
</table>
</td>
    <td class='inhoud_c' width='20%'>
      ".gmdate("H:i:s", $time)."
    </td>
</tr>   ";
                $i++;

To something like this, but I don't know how to do it: 对于这样的事情,但我不知道该怎么做:

<td class='inhoud_c' width='20%'>
  "if ($tijz >= 0){
      gmdate("H:i:s", $tijz);
   }
   else {
     echo "Time's Up!";
   }
</td>

So I want a if else statement inside echo, But when i try this the rest of my code doesn't work. 所以我想在echo中使用if else语句,但是当我尝试这个时,我的其余代码都不起作用。

You can try using ternary operator like this: 您可以尝试使用这样的三元运算符:

( ($tijz >= 0) ? gmdate("H:i:s", $tijz) : "Time's Up!" )

Then: 然后:

echo "
td class='inhoud_c' width='5%'>".$i."</td>
<td class='inhoud' width='25%'><a href='profile.php?x=".$naam."'>".$naam."</td>
<td class='inhoud_c' width='50%'>
<table border='0' cellspacing='0' style='margin: 0px;'>
    <tr>
   <td>
       <img src='".$icon."' alt='' border='0'>
  </td>
     <td>
         ".$land."
    </td>
</tr>
</table>
</td>
    <td class='inhoud_c' width='20%'>
      ". ( ($tijz >= 0) ? gmdate("H:i:s", $tijz) : "Time's Up!" ) ."
    </td>
</tr>   ";
                $i++;

You can use a ternary operator for if else or something like this 您可以使用三元运算符为的if else或类似的东西

<?php
if ($tijz >= 0) {
    echo gmdate("H:i:s", $tijz);
} else {
    echo "Time's Up!";
}
?>

Is this what you're looking for? 这是你在找什么?

<?php
echo $tijd > 0 ? gmdate('H:i:s', $tijd) : 'Times up!';
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM