I read Codeigniter 3 kernel code and came across this line:
isset($index) OR $index = array_keys($array);
How it works? Never seen such an assignment.
I read Codeigniter 3 kernel code and came across this line:
isset($index) OR $index = array_keys($array);
How it works? Never seen such an assignment.
The first part of the expression checks whether the variable $index contains any value other than NULL :
$index === NULL , then the first part of the expression returns false , so we should initialize the variable.$index !== NULL , then the variable has some value and the part after the OR skipped.Why exactly? - This is the principle of the operation of the computation of logical expressions in PHP, which allows us not to make unnecessary calculations that will not lead to a new result.
For example, the expression true OR false . The first part of the expression returns true , which means that the second part is meaningless, because regardless of the result, the result will be true . In the same way, in the expression false AND true there is no sense to watch the second part - the value of the expression will be false anyway
If instead of OR take AND , then in the expression true AND false PHP will scan both of its parts, since depending on the result of the second part, the value of the whole expression may change.
Source: https://ru.stackoverflow.com/questions/526807/
All Articles