Php Interview Question list 2

Q. How come the code works, but doesn’t for two-dimensional array of mine?
ANSWER: Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.

Q. What is the difference between characters 23 and x23?
ANSWER: The first one is octal 23, the second is hex 23.

Q. Would you initialize your strings with single quotes or double quotes?
ANSWER: Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

Q. With a heredoc syntax, do I get variable substitution inside the heredoc contents? ANSWER: Yes.
I want to combine two variables together:
$var1 = ‘Welcome to ‘;
$var2 = ‘’;
What will work faster? Code sample 1: $var 3 = $var1.$var2;
Or code sample 2: $var3 = “$var1$var2”;
Both examples would provide the same result – $var3 equal to “Welcome to”. However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.

Q. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
ANSWER: Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

Form More Information 

Leave a Reply

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

You are commenting using your 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