Saturday, November 19, 2011

PHP interview questions and answers


PHP interview questions and answers

1. What does a special set of tags <?= and ?> do in PHP?
Ans:The output is displayed directly to the browser.
2. Who is the father of PHP ?
Ans:Rasmus Lerdorf is known as the father of PHP.
3. How i can get ip address?
Ans:We can use SERVER var $_SERVER['SERVER_ADDR'] 
and getenv("REMOTE_ADDR") functions to get the IP address.
4.How do you define a constant?
Ans:Via define() directive, like define ("MYCONSTANT", 500);
5.How do you pass a variable by value?
Ans:Put an ampersand in front of it, like $a = &$val.
6.Will comparison of string "49" and integer 50 work in PHP?
Ans:Yes, internally PHP will cast everything to the integer type,
so numbers 49 and 50 will be compared.
7. I am trying to assign a variable the value of 0123, but it keeps
coming up with a different number, what’s the problem?
Ans:PHP Interpreter treats numbers beginning with 0 as octal.
8.What’s the difference between htmlentities() and htmlspecialchars()?
 Ans:htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. 
htmlentities translates all occurrences of character sequences that have different meaning in HTML.
9.In how many ways we can retrieve the data in the result set of MySQL using PHP?
Ans:We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc
10.How can we create a database using PHP and MySQL?
Ans:We can create MySQL database with the use of mysql_create_db("Database Name") 
11.Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"?
Ans:Yes we can use include("xyz.php") more than one time in any page. but it create a prob when xyz.php file contain some funtions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must incude it two time not a prob 
12.What is use of header() function in php ? 
Ans:The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen
13. Types of arrays in PHP?
Ans:In PHP, there are three kind of arrays:
1.Numeric array-->A numeric array stores each array element with a numeric index.
2.Associative array-->An associative array, each ID key is associated with a value.
3.Multidimensional array-->In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.







No comments:

Post a Comment

Note: Only a member of this blog may post a comment.