PHP: colon, endif, endwhile, endfor

WBOY
Release: 2016-08-08 09:24:50
Original
1046 people have browsed it

We often see a lot of strange PHP syntax in the templates of blogging programs such as wordpress, such as:

[php] view plaincopy

  1. if(empty($GET_['a'])): ?>
  2.  < font color="red">empty
  3. endif; ?>
For quite a few PHP enthusiasts, this is simply not possible. I've never seen them before. What are these? In fact, these are alternative syntaxes for PHP process control, but they are not commonly used.
Now I will give you a detailed explanation of the alternative syntax for PHP process control.
1. What is alternative syntax?
Simply put, they are some alternative ways of writing grammar.
2. Which syntaxes in PHP have alternative syntaxes?

Flow control statements such as if, while, for, forforeach, and switch have alternative syntax.
3. The basic form of alternative syntax:

Replace the left curly brace ({) with a colon (:), replace the right curly brace (}) with endif;, endwhile;, endfor;, endforeach; and endswitch respectively ;
Example:

[php] view plaincopy

  1. if ($a<0): ?>
  2. is a negative number
  3. endif ; ?>
  4. The above statement is equivalent to
  5. if ($a<0){ ?>
  6. It’s a negative number

4. No one is used to it, and what’s the use of having him so different?

Existence is reasonable, and it has its own uses. The place where these syntaxes can be used is in the code of a mixed PHP and HTML page. The benefits are as follows:
1) Make the HTML and PHP mixed page code cleaner and neater.
2) The process control logic is clearer and the code is easier to read.

The above introduces PHP: colon, endif, endwhile, endfor, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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