什么是:用于PHP [英] What is : used for in PHP

查看:70
本文介绍了什么是:用于PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始在wordpress中开发主题并在index.php上看到此代码 -





Just started developing themes in wordpress and saw this code on index.php -


<?php if (have_posts()) : ?>

		<?php while (have_posts()) : the_post(); ?>







什么是用于上面的代码?它做了什么?



我搜索但在互联网上找不到答案。




What is : used for in the above code ? What does it do ?

I searched but couldn't find the answer on the internet.

推荐答案

朋友,



当你想混合html和php但你不想使用echo或print时,这非常简单。然后你要做的是将html封装在一个php if-else块或者foreach中,或者像这样封锁这个



Hi friend,

This is very simple when you want to mix html and php but you don't want to use echo or print. Then what you do is encapsulate the html inside a php if-else block or foreach or for block like this

<?php if (isset(


_SESSION [' user'])):?>
<! - 这里有些HTML - >
<? php else ?>
<! - 此处有些HTML - >
<? php endif; ?>
_SESSION['user'])) : ?> <!-- Some HTML here --> <?php else : ?> <!-- Some HTML here --> <?php endif; ?>





这种方式不是使用像这样繁琐的东西:



This way instead of using something cumbersome like this :

<?php <br mode="hold" /?>  if (isset(


_SESSION ['user'])){
echo'<! - 这里有些HTML - > ';
else
echo'<! - 这里的一些HTML - > ';
}
?>
_SESSION['user'])) { echo '<!-- Some HTML here -->'; else echo '<!-- Some HTML here -->'; } ?>





在这个非常小的例子中,下面的代码看起来很简单,但是当你开始在这些echo方法中放入真正的标签和链接,整个代码很快就会变脏和不可读。



所以,这是一个更好的方法来使用以前的方式编码以生成更干净和可读的代码。简单对代码运行时间等没有太大影响。



如果,这是你需要的答案,请将其标记为已解决:)



问候

Tushar Srivastava



In this very small example, the code below seems simple but when you start to put real tags and links inside these echo methods, the whole code become dirty and unreadable very soon.

So, it is a better method to use the former way of coding to generate more clean and readable code. It simple has no big effect on code running time etc.

If, this is the answer you need then, please do mark it as solved :)

With Regards
Tushar Srivastava


这篇关于什么是:用于PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆