Home  >  Article  >  Backend Development  >  What are the ways to write php if

What are the ways to write php if

藏色散人
藏色散人Original
2021-11-03 09:49:554593browse

php There are 5 ways to write if, namely: 1. "if {...}else {...}"; 2. "if () :...else:...endif; "; 3. "...? true : false;"; 4. "if ()..."; 5. "...&&...".

What are the ways to write php if

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

What are the ways to write php if?

5 ways to write if statements in PHP

The code is as follows:

<?php
    // one
    if (condition) {
        ...
    } else {
        ...
    }
    // two
    if (condition) :
        ...
    else:
        ...
    endif;
    // three
    condition ? true : false ;
    // four if后面紧接着判断为true所执行的代码,可分两行写,只有一个分号
    if (condition) ... ;
    //five 使用短路与和短路或
    expression1 && expression2;
    expression1 || expression2;

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are the ways to write php if. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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