Home > Backend Development > PHP Tutorial > php中可以用:代表开始,用 end代表结束吗

php中可以用:代表开始,用 end代表结束吗

WBOY
Release: 2016-06-06 20:21:24
Original
1082 people have browsed it

php中可以用 :开始 用end结束吗?

<code>  <?php foreach($categories as $category):?>
  <tr align="center" class="0" id="0_6">
     <td width="10%">
    <?php echo $category['id'];?>
    </td>
    <td align="left" class="first-cell">
    <?php echo str_repeat('    ',$category['level']*2),$category['cat_name'];?>
    </td>
    <td width="10%">
    <?php echo $category['goods_inv'];?>
    </td>

    <td width="10%" align="right">
    <?php echo $category['sort'];?>
    </td>

    <td width="24%" align="center">
      <a href="category.php?act=edit&id=<?php%20echo%20%24category%5B'id'%5D;?>">编辑</a> |
      <a href="category.php?act=del&id=<?php%20echo%20%24category%5B'id'%5D;?>" onclick="return confirm('你确定删除么?');" title="移除">移除</a>
    </td>

  </tr>
  <?php endforeach;?></code>
Copy after login
Copy after login

例如这段代码中:在开头foreach用 :开始
在结尾中用 end foreache结束,能具体讲讲:跟 end 这两个怎么用吗?

回复内容:

php中可以用 :开始 用end结束吗?

<code>  <?php foreach($categories as $category):?>
  <tr align="center" class="0" id="0_6">
     <td width="10%">
    <?php echo $category['id'];?>
    </td>
    <td align="left" class="first-cell">
    <?php echo str_repeat('    ',$category['level']*2),$category['cat_name'];?>
    </td>
    <td width="10%">
    <?php echo $category['goods_inv'];?>
    </td>

    <td width="10%" align="right">
    <?php echo $category['sort'];?>
    </td>

    <td width="24%" align="center">
      <a href="category.php?act=edit&id=<?php%20echo%20%24category%5B'id'%5D;?>">编辑</a> |
      <a href="category.php?act=del&id=<?php%20echo%20%24category%5B'id'%5D;?>" onclick="return confirm('你确定删除么?');" title="移除">移除</a>
    </td>

  </tr>
  <?php endforeach;?></code>
Copy after login
Copy after login

例如这段代码中:在开头foreach用 :开始
在结尾中用 end foreache结束,能具体讲讲:跟 end 这两个怎么用吗?

见 http://php.net/manual/zh/control-structures.alternative-syntax.php

这种语法一般在html混用中使用
语法结构就是以冒号代替起如括号,以 end ** 结束,一般基本的语法都可以用这种方式,比如if,switch,foreach等这些,形式大抵如下

<code><?php if (condition): ?>
...
<?php else: ?>
...
<?php endif ?>
</code>
Copy after login

这是语法的一部分,详见vimac的回答。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template