Wednesday, July 29, 2009

Php Interview Questions and Answers, Php Interview Question, Technical Php Questions

Q1) What is PHP ?
Ans: PHP also termed as Hypertext preprocessor is a Server-side HTML embedded scripting language.

Q2) How can we get second of the current time using date function?
Ans: echo $second = date("s");
?>

Q3) How can we know the number of elements in an array using php?
Ans: There are two ways:
1) sizeof($myarray) - This function is an alias of count()

Q4) What are the different functions in sorting an array?
Ans: asort()
arsort()
ksort()
krsort()
uksort()
sort()
natsort()

Q5) What would the following code print to the browser? And Why?
Ans:
$num = 10;
function multiply()
{
$num = $num * 10;
}
multiply();
echo $num;

Q6) What is mean by LAMP?
Ans: LAMP is the combination of Linux, Apache, MySQL and PHP.

Q7) How can you get round the stateless nature of HTTP using PHP?
Ans: using Sessions in PHP

Q8) What function can you use to open a file for reading and writing?
Ans: fopen();

Q9) What function would you use to redirect the browser to a new page?
Ans:header()

Q10) Are PHP function names casesensitive?
Ans: No, It is not case sensitive functions.
Q11) What is scandir() ?
Ans: List files and directories inside the specified path by default files order will be ascending.

Q12) What output do you get here?
$array=array(5,5,5);
echo $r=array_pad($array,5,2);
?>
Ans:Array

Q13) What is the output here?
">var_dump(0 == "a");
?>

Q14) What is the output below mentioned?
$text = 'php m programmer';
echo strpbrk($text, 'm');
?>

Q15) What is the output below mentioned ?
$string = 'APPLE';
echo stristr($string, 97);
?>

Q16) What is the relation between the versions?

Ans: PHP 2.0 is an early and no longer supported version of PHP. PHP 3 is the successor to PHP 2.0 and is a lot nicer. PHP 4 is the current generation of PHP, which uses the Zend engine under the hood. PHP 5 uses the Zend engine 2 which, among other things, offers many additional OOP features.

Q17) What is the output for the following script ?
$s=”hihihi”;
echo $s. “ welcome”.$s;
a) syntax error
b) runtime error
c) all of the above

Q18) php comments will be?
a) //
b) /* fgfg */
c) All of the above
d) First one

Q19) What is the difference between require and include?
Ans: Require function is used to embed another file in php, it gives fatal error if the file does not exists.Include function is also used to embed another file in php, but it gives warning if the file does not exists.

Q20) php supports following database ??

a) Solid & oracle
b) mysql
c) None of the above
d) All of the above

Q21) How do you get the user’s IP address in PHP?
Ans: Using the server variable: $_SERVER[’REMOTE_ADDR’]

Q22) How to count no of words in a file without using loop ?

Ans: Suppose file name is “abc.txt” containing some string.

//First make the array ($lines) of the file abc.txt using below function .
$lines = file('abc.txt'); //Secondly use this function to count no. of words using below function. print_r(array_count_values($lines));
?>

No comments:

Post a Comment