: +91-9350865940
Testimonials
Thank you Dass infotech for the outstanding service and support you provide my business. I very much appreciate the high level of programming skills and the friendly and approachable manner of your staff. Nothing is ever a problem. I look forward to working with you well into the future!
Dass, Owner/Manager

PHP Basic interview Questions
Q. Who is the father of PHP ?
A. Rasmus Lerdorf is known as the father of PHP.
 
Q. What is a Session in PHP?
A. A PHP session is no different from a normal session. It can be used to store information on the server for future use. However this storage is temporary and is flushed out when the site is closed. Sessions can start by first creating a session id (unique) for each user. Syntax : session_start() E.g.
storing a customer’s information.
 
Q. What is PHP Session Variables
A. A PHP session variable is used to hold values of the current session. A session needs to be started first.
E.g.
session_start();
$_SESSION['sample']=1;      // store session data
They can be used to hold information about a single user that is applicable to all web pages.
 
Q. Explain the difference between $message and $$message in PHP
A. $message is a variable and $$message is a variable of another variable.
E.g.
$Message = "YOU";
$you= "Me";
echo $message //Output:- you
echo $$message //output :-Me
$$message allows the developer to change the name of the variable dynamically.
 
Q. What’s the difference between include and require?
A. It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
 
Q. Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?
A. In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.
 
Q. How do you define a constant?
A. Via define() directive, like define ("MYCONSTANT", 100);
 
Q. How do you pass a variable by value?
A. Just like in C++, put an ampersand in front of it, like $a = &$b
 
Q. What’s the difference between accessing a class method via -> and via ::?
A. :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.
 
Q.Would you initialize your strings with single quotes or double quotes?
A.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. For printing out strings, there are echo, print and printf. Explain the differences.
A. echo :- is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like: echo 'Welcome ', 'to', ' ', 'TechInterviews!'; and it will output the string "Welcome to TechInterviews!"
print :- does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP.
printf :-is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.
 
Q. What’s the difference between htmlentities() and htmlspecialchars()? -
A.htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
 
Q. What’s the difference between md5(), crc32() and sha1() crypto on PHP? -
A.major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.
 
Q. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()? -
A. 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.
 
Q. Give the syntax of REVOKE commands?
A. The generic syntax for revoke is as following,
REVOKE [rights] on [database] FROM [username@hostname]
Now rights can be:
  1. ALL privileges
  2. Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all database by using *.* or some specific database by database.* or a specific table by database.table_name.
 
Q. Why doesn’t the following code print the newline properly?
$str = ‘Hello, there.\nHow are you?\nThanks for visiting techpreparation’; print $str;
A. Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.
 
Q. What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?
A. When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn't display these values.
 
Q. What is the difference between the functions unlink and unset?
A. unlink() is a function for file system handling. It will simply delete the file in context.
unset() is a function for variable management. It will make a variable undefined.
 
Q. How come th code works, but doesn’t for two-dimensional array of mine?
A. 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 \023 and \x23?
A. The first one is octal 23, the second is hex 23.
 
Q. What’s the output of the ucwords function in this example?
A. $formatted = ucwords("TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS");
print $formatted; What will be printed is TECHPREPARATIONS IS COLLECTION OF INTERVIEW QUESTIONS. ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.
 
Q. What’s the difference between htmlentities() and htmlspecialchars()?
A.htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
 
Q. How can we destroy the session, how can we unset the variable of a session?
A.session_unregister() - Unregister a global variable from the current session
session_unset() - Free all session variables
 
Q.What are the different functions in sorting an array?
A.Sorting functions in PHP:
  • asort()
  • arsort()
  • ksort()
  • krsort()
  • uksort()
  • sort()
  • natsort()
  • rsort()
 
Q. How can we know the count/number of elements of an array?
A.2 ways:
  • sizeof($array) - This function is an alias of count()
  • count($urarray) - This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1.
 
Q. What are the different components used in PHP for formatting?
A.The components that are used in PHP for formatting are as follows:
  1. it tells the start of the formatting instruction.
  2. Padding character (pad): is used to fill out the string when the value to be formatted is smaller than the width assigned. Pad can be a space, a 0, or any character preceded by a single quote (‘).
  3. A symbol meaning to left-justify the characters. If this is not included, the characters are right-justified.
  4. width: The number of characters to use for the value. If the value doesn’t fill the width, the padding character is used to pad the value. For example, if the width is 5, the padding character is 0, and the value is 1, the output is 00001.
  5. dec: The number of decimal places to use for a number. This value is preceded by a decimal point.
  6. type: The type of value. Use s(string) for string, f (float) for numbers that you want to format with decimal places.
 
Q. What is the use of super-global arrays in PHP?
A.Super global arrays are the built in arrays that can be used anywhere. They are also called as auto-global as they can be used inside a function as well. The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array. This $HTTP_SERVER_VARS check your php.ini setting for long arrays.
 
Q. What is the use of $_Server and $_Env?
A.$_SERVER and $_ENV arrays contain different information. The information depends on the server and operating system being used. Most of the information can be seen of an array for a particular server and operating system. The syntax is as follows:
foreach($_SERVER as $key =>$value)
{ echo “Key=$key, Value=$value\n”; }
 
Q. How to Set cookie in php ?
A. Cookies in PHP can be set using the setcookie() function. This must appear before the HTML tag,
Syntax:
Setcookie(name, value, expire, path, domain);
Example: here, the cookie name sample is assigned a value jim. The cookie expires after an hour.
Setcookie(“sample”, “jim”, time()+3600);
 
Q.What is a Persistent Cookie?
A.Cookies are used to remember the users. Content of a Persistent cookie remains unchanged even when the browser is closed. ‘Remember me’ generally used for login is the best example for Persistent Cookie.
How to set cookies? How to reset/destroy a cookie?
 
Q.Reset/destroy cookie
A. Cookies can be deleted either by the client or by the server. Clients can easily delete the cookies by locating the Cookies folder on their system and deleting them. The Server can delete the cookies in two ways:
  • Reset a cookie by specifying expiry time
  • Reset a cookie by specifying its name only
 
Q. How can we submit a form without a submit button?
A. Java script submit() function is used for submit form without submit button on click call document.formname.submit()
 
Q. In how many ways we can retrieve the data in the result set of MySQL using PHP?
A. We can do it by 4 Ways 1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object 4. mysql_fetch_assoc
 
Q. What is the difference between mysql_fetch_object and mysql_fetch_array?
A. mysql_fetch_object() is similar tomysql_fetch_array(), with one difference – an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
 
Q. What are the differences between Get and post methods.
A. There are some defference between GET and POST method 1. GET Method have some limit like only 2Kb data able to send for request But in POST method unlimited data can we send 2. when we use GET method requested data show in url but Not in POST method so POST method is good for send sensetive request
 
Q. How can we extract string “sandykadam.com ” from a string “http://info@sandykadam.com using regular expression of PHP?
A. preg_match(“/^http:\/\/.+@(.+)$/”,”http://info@sandykadam.com”,$matches); echo $matches[1];
 
Q. How can we create a database using PHP and MySQL?
A. We can create MySQL database with the use of mysql_create_db(“Database Name”)
Site Navigation >