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){}
:
php
if(true){ //这个花括号里的代码都会执行}
and if(true)
:
php
if (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可为空