About if statement
益伦
益伦 2018-12-30 23:24:17
0
3
1182

function read_file_array($filename, $skip_empty_lines = false)
{
// Check whether the file is a normal file and check whether the file is readable
if (is_file($filename) && is_readable($filename )) {
                                                                                                                                                                                but but            #} Else {
// Query file content
Return file ($ FILENAME);
}
}
Return "This file cannot be read!"
var_dump(read_file_array('text1.txt'));




Question: Teacher Wei Xiaobao, the last line in the read_file_array function here

return " The file cannot be read!";


Why don't this behavior need to be wrapped with else()? In the previous courses, the if statement was not followed by elseif() and the return output was directly performed. Although there is no problem for the time being, it is not impossible. Is it consistent with norms or logic? ?

益伦
益伦

reply all(2)
一路向北丶

return jumps out of the function, so return can only be executed once in a function, so it will be fine without adding else

  • reply This is a simple explanation, thank you bro!
    益伦 author 2019-01-08 17:04:57
韦小宝

The last one is useless else is just a matter of efficiency and does not violate the standards and logic

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template