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

What are the ways to write php if

藏色散人
Release: 2023-03-13 17:04:02
Original
4704 people have browsed it

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;
Copy after login

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!

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