Search the Community
Showing results for tags 'return false'.
-
Php Gurus, Why is it that the RETURN FALSE only echos the last non-matched item ? I had like this: $banned_words = array("0","1","2","3","4","5","6","7","8","9"); $content = "f"; //Tailored for no match to be found. As you can see, the script is tailored not to find any matches. The RETURN FALSE does not show you result like this: Script 2a - No Match: 0 Script 2a - No Match: 1 Script 2a - No Match: 2 Script 2a - No Match: 3 Script 2a - No Match: 4 Script 2a - No Match: 5 Script 2a - No Match: 6 Script 2a - No Match: 7 Script 2a - No Match: 8 Script 2a - No Match: 8 But only shows you like this: Script 2a - No Match: 9 <?php //script 2a: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string $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; //What is the mystery behind the "return true" ? } } echo "Script 2a - No Match: $ban";?><br><?php return false; //What is the mystery behind the "return false" ? //Showing result: No match: 9. //Why is it not showing the other non-matches ? Why showing only the last non-match ? ?> <br>
- 15 replies
-
- return false
- php
-
(and 2 more)
Tagged with:
-
I've never understood the application of return true and return false after function calls in JavaScript. Could somebody please explain their meaning. This is a very simple script which will create a popup window for each links in an html document. function createPopup(e) { 'use strict'; // Get the event object: if (typeof e == 'undefined') var e = window.event; // Get the event target: var target = e.target || e.srcElement; // Create the window: var popup = window.open(target.href, 'PopUp', 'height=100,width=100,top=100,left=100,location=no,resizable=yes,scrollbars=yes'); // Give the window focus if it's open: if ( (popup !== null) && !popup.closed) { popup.focus(); return false; // Prevent the default behavior. } else { // Allow the default behavior. return true; } } // End of createPopup() function. // Establish functionality on window load: window.onload = function() { 'use strict'; // Add the click handler to each link: for (var i = 0, count = document.links.length; i < count; i++) { document.links[i].onclick = createPopup; } // End of for loop. }; // End of onload function. The only part of the script that doesn't make sense here is the return true/false. Why do we use return true or return false after calling a JavaScript function?
- 3 replies
-
- return true
- return false
-
(and 2 more)
Tagged with: