Search the Community
Showing results for tags 'true'.
-
Folks, Is it true that once the RETURN shows you a result, be it TRUE or FALSE, the script gets executed no further in the script flow ? Did I understand it correctly here: http://php.net/manual/en/functions.returning-values.php I had 2 scripts (2b & 2a) in the same file like so ... My questions are in the comments. If anyone knows the answers then kindly respond. Thanks <?php /* ERROR HANDLING */ declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //script 2b: $banned_words = array("0","1","2","3","4","5","6","7","8","9"); $content = "4"; foreach ($banned_words as $ban) { if (stripos($content, $ban) !== FALSE) { echo "Script 2b - Match: $ban";?><br><?php return true; //QUESTION 1: What is the mystery behind the "return true/false" ? Why the script does not flow below this point to the rest of the script plus to the other script script 2a ? } } echo "Script 2b - No Match: $ban";?><br><?php return false; //What is the mystery behind the "return false" ? //Showing result: Script 2b - Match: 4. //QUESTION 2: Why is it not showing the other matches & non-matches ? Why showing only the first match ? ?> <br> <?php //script 2a: $banned_words = array("0","1","2","3","4","5","6","7","8","9"); $content = "f"; //Tailored for no match to be found. foreach ($banned_words as $ban) { if (stripos($content, $ban) !== FALSE) { echo "Script 2a - Match: $ban";?><br><?php return true; } } echo "Script 2a - No Match: $ban";?><br><?php return false; ?> <br>
