PHP General Questions & Answers

Posted: April 23, 2013 in PHP

Question1: What are the differences between require and include, include_once?
Answer:
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.

The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.

Question2: What are the differences between include() and include_once() functions?
Answer: include_once() will use the specified file only once. include and require will use the specified file as many time we want. If include_once() is used before with same name, it can not done again

Question3: What is difference between echo and print?
Answer: print and echo are more or less the same; they are both language constructs that display strings. The differences are : print has a return value of 1 so it can be used in expressions whereas echo has a void return type; echo can take multiple parameters, although such usage is rare; echo is slightly faster than print. (Personally, I always use echo, never print.)

Question4: What is the difference between an if statement and a switch statement?
Answer: The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s