php - Which way is more efficient? -


I will try to keep it simple. I've created twp functions that do some tests:

 < Code> // user valid function (validusr) {returns true; // or false, depends} // user db function indbusr () {true;   

Later, I have this

  if valid ($ myval)) validusr ($ myval) Returns; And if (! Mybie) ($ myval) returns; And come back to the truth; However, it does not look good because I am calling the function 2 times: to test once  $ myval , and when I return it, but if I say, value like this Save From:  
  $ result1 = Valid ($ myval); $ Result2 = indbusr ($ myval); If (! $ 1 result) returns $ result1; And if (! $ 2 result) returns $ result2; And come back to the truth;   

There may be cases when the second statement never runs because because it is always true, which calls the other function unusable.

So which one is more efficient? What is the value and what does it store the risk that it is not being used or calls the function twice when needed?

The argument boils down to doing this:

  If the user is valid And in the database, return true, otherwise, return false;   

You can take advantage of PHP's internal optimizer to define the call function. Using it: Return (valid ($ myval) & amp; amp; amp; amp;; Indian ($ myval));

PHP will execute the first task and look forward to expression. If the function returns true then it will run on the next function. If it returns false returns then the false will be done, whichever returns the next function, call it php and return false immediately. Will not bother to do so. $ a || $ b} someFunction ($ c) ) will return true as soon as it returns to true in a sequence Value (Thank you for highlighting it!)

It's great if your actions do not have any side effects if you are trusting your second function then true / false question Apart from answering, there will be some other effect, it will not work for you.

You can work on it - instead of trying to change the values ​​work and see what happens when you run it.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -