Heim  >  Artikel  >  Backend-Entwicklung  >  php中可以用:代表开始,用 end代表结束吗

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

WBOY
WBOYOriginal
2016-06-06 20:21:241028Durchsuche

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>

例如这段代码中:在开头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>

例如这段代码中:在开头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>

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn