Differences between phpif () {} And if ()

Source: Internet
Author: User
I encountered this problem when I was studying PHP today. {Code...} shows the result {code...} does not show the result. Isn't the code at both ends the same? I encountered this problem when I was studying PHP today.

Function filter ($ fun) {for ($ I = 0; $ I <= 100; $ I ++) {if (call_user_func_array ($ fun, array ($ I ))) continue; echo $ I."
";}}// Calculate the divisible function one ($ num) {return $ num % 3 = 0;} // flip the string function two ($ num) {return $ num = strrev ($ num);} filter ("one"); echo"
"; Filter ('two ');

Display result

Function filter ($ fun) {for ($ I = 0; $ I <= 100; $ I ++) {if (call_user_func_array ($ fun, array ($ I ))) {continue; echo $ I."
";}}// Returns the divisible function one ($ num) {return $ num % 3 = 0;} // flip the string function two ($ num) {return $ num = strrev ($ num);} filter ("one"); echo"
"; Filter ('two ');

The result is not displayed. Isn't the code at both ends the same?

Reply content:

I encountered this problem when I was studying PHP today.

Function filter ($ fun) {for ($ I = 0; $ I <= 100; $ I ++) {if (call_user_func_array ($ fun, array ($ I ))) continue; echo $ I."
";}}// Calculate the divisible function one ($ num) {return $ num % 3 = 0;} // flip the string function two ($ num) {return $ num = strrev ($ num);} filter ("one"); echo"
"; Filter ('two ');

Display result

Function filter ($ fun) {for ($ I = 0; $ I <= 100; $ I ++) {if (call_user_func_array ($ fun, array ($ I ))) {continue; echo $ I."
";}}// Returns the divisible function one ($ num) {return $ num % 3 = 0;} // flip the string function two ($ num) {return $ num = strrev ($ num);} filter ("one"); echo"
"; Filter ('two ');

The result is not displayed. Isn't the code at both ends the same?

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

Equivalent

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

Whether it is true or not, php will be executed. php is not python. It is not to say that indentation is a statement block.

Php's if is the same as C's if.

If you do not increase the brackets, you can use semicolons (;). Braces (_) are added to the braces.

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

This program is wrong, becauseecho $i."
";
Will never be executed

if(true){}:

phpIf (true) {// the code in the curly braces will be executed}

Whileif(true):

phpIf (true) echo (233); // only this echo (233); it belongs to if to judge echo time ();

The difference isif(true)Only the following sentence must be followed: the condition is that the Code is actually executed, andif(true){}The code in the curly braces of is the Execution Code with a condition, andCan be empty

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.