About the difference between PHP if () {} and if ()

Source: Internet
Author: User
Tags learn php
This is a problem when you learn PHP today.

    function filter($fun){                for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i)))                            continue;                            echo $i."
"; } } //求被三整除 function one($num){ return $num % 3 ==0; } //翻转字符串 function two($num){ return $num == strrev($num); } filter("one"); echo "
"; filter('two');

Show results

    function filter($fun){                for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i))){                            continue;                            echo $i."
"; } } } //求被三整除 function one($num){ return $num % 3 ==0; } //翻转字符串 function two($num){ return $num == strrev($num); } filter("one"); echo "
"; filter('two');

The results are not displayed. Is the above two lines not the same meaning?

Reply content:

This is a problem when you learn PHP today.

    function filter($fun){                for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i)))                            continue;                            echo $i."
"; } } //求被三整除 function one($num){ return $num % 3 ==0; } //翻转字符串 function two($num){ return $num == strrev($num); } filter("one"); echo "
"; filter('two');

Show results

    function filter($fun){                for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i))){                            continue;                            echo $i."
"; } } } //求被三整除 function one($num){ return $num % 3 ==0; } //翻转字符串 function two($num){ return $num == strrev($num); } filter("one"); echo "
"; filter('two');

The results are not displayed. Is the above two lines not the same meaning?

    for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i)))                            continue;                            echo $i."
"; }

Equivalent to

    for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i))){                            continue;                       }                       echo $i."
"; }

No matter if your if is true, will execute, PHP is not python oh. Not that indentation is just a block of statements.

PHP if is the same as if C.

Do not increase the parentheses to the semicolon, and the curly brace is the thing inside the curly braces.

for($i=0; $i<=100; $i++){                       if(call_user_func_array($fun, array($i))){                            continue;                            echo $i."
"; } }

This procedure is wrong, because it will echo $i."
";
never be executed.

if(true){}:

phpif(true){    //这个花括号里的代码都会执行}

and if(true) :

phpif (true) echo(233);//只有这个echo(233);才是属于if判断echo time();

The difference is that there is only the next if(true) sentence and must have a condition for the real execution of the code, and if(true){} the curly braces code is the conditional execution code, and可为空

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.