pHp Interview question bank

1. What is MIME?
Answer. Multipurpose Internet Mail Extensions (MIME) is an Internet standard that extends the format of file. It describe the basically content type of a give file.
eg.
application/pdf
application/zip
application/excel
2. What is the default session time in PHP?
Answer. 1440 sec
3. What is the difference between using copy() and move() function in PHP?
Answer. copy function copy the file from source to destination. it means the file also exists on source after uploading.
copy(source,destination)
move function cut the file from source and copy to destination. it means the file also does not exists on source after uploading.
move(source,destination)

4. How can we submit a form without a submit button?
Answer : by javascript function form.submit();

5. how we post the data using curl?
Answer :
<?php
$url="www.site.com/post.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://$url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, "mode=listing&step=update");
curl_exec ($ch);
curl_close ($ch);
?>

6. What is displayed when the following script is executed?
<?php
define (myvalue, "10");
$myarray[10] = "Dog";
$myarray[] = "Human";
$myarray['myvalue'] = "Cat";
$myarray["Dog"] = "Cat";
print "The value is: ";
print $myarray[myvalue]."\n";
?>

A. The value is: Dog
B. The value is: Cat
C. The value is: Human
D. The value is: 10
E. Dog
F. None of the Above

Answer: _A__

7. What is the output of the following script?

<?php
$a = 10;
$b = 20;
$c = 4;
$d = 8;
$e = 1.0;
$f = $c + $d * 2;
$g = $f % 20;
$h = $b - $a + $c + 2;
$i = $h << $c;
$j = $i * $e;
print $j;
?>

A. 128
B. 42
C. 242.0
D. 256
E. 342
F. None of the Above

Answer: _D__

8. Which values should be assigned to the variables $a, $b and $c in order for the following script to display the string Hello, World!?

<?php
$string = "Hello, World!";
$a = ?;
$b = ?;
$c = ?;
if($a) {
if($b && !$c) {
echo "Goodbye Cruel World!";
} else if(!$b && !$c) {
echo "Nothing here";
}
} else {
if(!$b) {
if(!$a && (!$b && $c)) {
echo "Hello, World!";
} else {
echo "Goodbye World!";
}
} else {
echo "Not quite.";
}
}
?>

A.False, True, False
B.True, True, False
C.False, True, True
D.False, False, True
E.True, True, True
F. None of the Above

Answer: _D__

9. Consider the following segment of code:

<?php
define("STOP_AT", 1024);
$result = array();
/* Missing code */
{
$result[] = $idx;
}
print_r($result);
?>

What should go in the marked segment to produce the following array output?

Array
{
[0] => 1
[1] => 2
[2] => 4
[3] => 8
[4] => 16
[5] => 32
[6] => 64
[7] => 128
[8] => 256
[9] => 512
}

A. foreach($result as $key => $val)
B. while($idx *= 2)
C. for($idx = 1; $idx < STOP_AT; $idx *= 2)
D. for($idx *= 2; STOP_AT >= $idx; $idx = 0)
E. while($idx < STOP_AT) do $idx *= 2
F. None of the Above

Answer: _C__

10. Choose the appropriate function declaration for the user-defined function is_leap(). Assume that, if not otherwise defined, the is_leap function uses the year 2000 as a default value:

<?php
/* Function declaration here */
{
$is_leap = (!($year %4) && (($year % 100) ||
!($year % 400)));

return $is_leap;
}

var_dump(is_leap(1987)); /* Displays false */
var_dump(is_leap()); /* Displays true */

?>

A. function is_leap($year = 2000)
B. is_leap($year default 2000)
C. function is_leap($year default 2000)
D. function is_leap($year)
E. function is_leap(2000 = $year)
F. None of the Above

Answer: __A_

11. What is the value displayed when the following is executed? Assume that the code was executed using the following URL:
testscript.php?c=25

<?php
function process($c, $d = 25)
{
global $e;
$retval = $c + $d - $_GET['c'] - $e;
return $retval;
}
$e = 10;
echo process(5);
?>

A. 25
B. -5
C. 10
D. 5
E. 0
F. None of the Above

Answer: __D_

12. Run-time inclusion of a PHP script is performed using the ________ construct, while compile-time inclusion of PHP scripts is performed using the _______ construct.

A.include_once, include
B.require, include
C.require_once, include
D.include, require
E.All of the above are correct
F. None of the Above

Answer: _B__

13. What does <? echo count ("123") ?> print out?
A. 3
B. False
C. Null
D. 1
E. 0
F. None of the Above

Answer: __D_

14. Given
$text = 'Content-Type: text/xml';
Which of the following prints 'text/xml'?

A. print substr($text, strchr($text, ':'));
B. print substr($text, strchr($text, ':') + 1);
C. print substr($text, strpos($text, ':') + 1);
D. print substr($text, strpos($text, ':') + 2);
E. print substr($text, 0, strchr($text, ':'));.
F. None of the Above

Answer: _D__

15. The code below __________ because __________.

&lt?php

class Foo
{

?>

&lt?php

function bar()
{
print "bar";
}

}

?>

A. will work, class definitions can be split up into multiple PHP blocks.
B. will not work, class definitions must be in a single PHP block.
C. will not work, class definitions must be in a single file but can be in multiple PHP blocks.
D. will work, class definitions can be split up into multiple files and multiple PHP blocks.
E. None of the Above

Answer: _B__