简体   繁体   English

PHP - 如果某事等于某事,那么回应一些东西

[英]PHP - if something is equal to something then echo something

I'm quite new to PHP now that I've started working with wordpress. 我现在已经开始使用wordpress了,我对PHP很陌生。

I'm trying to get something to work by using 'if' 我试图通过使用'if'来获得一些工作

Essentialy what I'm wanting to do is 本质上我想要做的是

If the status is equal to Open then return <a href="#" id="flashing">Link</a> If the status is not equal to Open then return <a href="#">Link</a> 如果状态等于“打开”,则返回<a href="#" id="flashing">Link</a>如果状态不等于“打开”,则返回<a href="#">Link</a>

Here's what I think would work: 这是我认为可行的:

<?php
   if ($status) == (open) {
     echo "id=flashing"
   }
?>

Obviosuly, I'm assuming this doesn't work but what I'm wanting to do is create a link 很明显,我认为这不起作用,但我想要做的是创建一个链接

Any help? 有帮助吗?

This is a really basic PHP syntax question; 这是一个非常基本的PHP语法问题; please read some documentation, and look at some examples before asking for help with every piece of code you write. 请阅读一些文档,并在向您编写的每段代码寻求帮助之前查看一些示例。

There is a comprehensive online manual for PHP , with many examples. 一个全面的PHP在线手册 ,有很多例子。 It is available in multiple translations, in case English is not your first language. 如果英语不是您的第一语言,它有多种翻译版本。

Things you have wrong in your example, with links to relevant pages of the manual: 您的示例中出错的地方,以及指向相关页面的链接:

The text of your question also confuses return and echo , which have very different meanings. 你的问题的文本也混淆了returnecho ,它们的含义非常不同。

Does this help? 这有帮助吗?

if ($status == 'open') {
  echo '<a href="#" id="flashing">Link</a>';
} else {
  echo '<a href="#" >Link</a>';
}

Just use the following code: 只需使用以下代码:

<?php
    if ($status == 'Open') {
      echo '<a href="#" id="flashing">Link</a>';
    } 
    else {
      echo '<a href="#" >Link</a>';
    }
?>
<?php
if ($status == 'open') 
{
   echo '<a href="link" id="flashing">Link</a>';
}
else
{
   echo '<a href="link" >Link</a>';
}
?>

假设Open是一个字符串,它可以像这样写(或者替代其他答案):

echo '<a href="#" '.(($status == 'Open') ? 'id="flashing"':'').'>Link</a>';

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

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