Monday, April 8, 2013

PHP Interview Questions for 0 - 1.5 years Experienced Developer

Hello friends,

Today In Developer's Blog, I am going to give you the Questions and Answers for the Interview.


I am sure it will help you a lot. Even if you are not preparing for any interview, but you can still read this for your knowledge and you can test yourself.



1. Which of the following functions allows you to store session data in a database?

A. session_start();

B. session_set_save_handler();

C. mysql_query();

D. You cannot store session data in a database.
Answer : B


2.
What will the following script output?


<?php

$x = 3 - 5 % 3;

echo $x;
?>

A. 2

B. 1

C. Null

D. True

E. 3
Answer : B
 



3.
Which data type will the $a variable have at the end of the following script?

<?php

$a = “1”;
?>

A. (int) 1

B. (string) “1”

C. (bool) True

D. (float) 1.0

E. (float) 1

Answer : B



4. What will the following script output?

<?php
$a = 1;
$a = $a-- + 1;
echo $a;
?>

A. 2

B. 1

C. 3

D. 0

E. Null
Answer : A


 5.  
What will the following script output?

<?php

class a {     

    private $c;     

    public function a($pass) {
         $this->c = $pass;
     }  
 

    public function print_data() { 
 
         echo $this->$c;
     }
 

 }  
 

 $a = new a(10);  
 
 $a->print_data();

?>

A. An error

B. 10

C. “10”

D. Nothing

E. A warning
Answer : A



6.   How do I find out the number of parameters passed into function?

A.    By using func_num_args()

B.    By using func_get_arg()

C.    By using func_get_args()

D.    None of the above
Answer : A


7.  What will the following script output?

<?php
error_reporting(E_ALL);
class a {
   var $c;
   function a() {
       $this->c = 10;
   }
}
class b extends a {
   function print_a() {
       echo $this->c;
   }
}
$b = new b;
$b->print_a();
?>

A. Nothing

B. An error because b does not have a constructor

C. 10

D. NULL

E. False
Answer : C


8. Is it possible to pass data from PHP to JavaScript?

A. No, because PHP is server-side, and JavaScript is client-side.

B. No, because PHP is a loosely typed language.

C. Yes, because JavaScript executes before PHP.

D. Yes, because PHP can generate valid JavaScript
Answer : D

9. Which types of form elements can be excluded from the HTTP request?


A. text, radio, and check box

B. text, submit, and hidden

C. submit and hidden

D. radio and check box


Answer : D




10.  When processing the form, what is the difference between a hidden form element and a non-hidden one, such as a text box?


A. The hidden form element does not have a name.

B. There is no difference.

C. The hidden form element does not have a value.

D. The hidden form element is excluded from the request.
Answer : B





11. Which of the following form element names can be used to create an array in PHP?

A. foo

B. [foo]

C. foo[]

D. foo[bar]
Answer : C,D



12. When an expiration date is given in a Set-Cookie header, what is the resulting behavior in subsequent requests?

A. If the expiration date has expired, the cookie is not included.

B. The behavior is the same; the expiration date is included in the Cookie
header, and you can access this information in the $_COOKIE superglobal
array.

C. The cookie persists in memory until the browser is closed.

D. The cookie is deleted and therefore not included in subsequent requests.
Answer : A





13. If you set a cookie with either setcookie() or header(), you can immediately check to see whether the client accepted it.

A. True, you can check the $_COOKIE superglobal array to see if it contains the
value you set.

B. True, but only if register_globals is enabled.

C. False, you can only use setcookie() if you need to test for acceptance.
Using header() does not work.

D. False, you must wait until you receive another HTTP request to determine
whether it includes the Cookie header.
Answer : D

14. Why must you call session_start() prior to any output?

A. Because it is easy to forget if not placed at the top of your scripts.

B. Because you can no longer access the session data store after there has been output.

C. Because session_start() sets some HTTP headers.

D. Because calling session_start() causes the HTTP headers to be sent.


Answer : C
 


15. Which of the following represents the proper way to set a session variable?

A. $_SESSION[‘foo’] = ‘bar’;

B. session_start();

C. session_set_save_handler (‘myopen’, ‘myclose’, ‘myread’,‘mywrite’, ‘mydelete’, ‘mygarbage’);

D. $foo = $_SESSION[‘foo’];


Answer : A
  

16. Which of the following types can be used as an array key? (Select three.)

A. Integer

B. Floating-point

C. Array

D. Object

E. Boolean
Answer : A,C,D

 
17. Which of the following functions can be used to sort an array by its keys in descending order?

A. sort

B. rsort

C. ksort

D. krsort

E. reverse_sort


Answer : D




18. What will the following script output?



<?php

$a = array (‘a’ => 20, 1 => 36, 40);

array_rand ($a);

echo $a[0];

?>

A. A random value from $a

B. ‘a’

C. 20

D. 36

E. Nothing


Answer : E



19.  Given

$email = ‘bob@example.com’;
which code block will output example.com?

A. print substr($email, -1 * strrpos($email, ‘@’));

B. print substr($email, strrpos($email, ‘@’));

C. print substr($email, strpos($email, ‘@’) + 1);

D. print strstr($email, ‘@’);
Answer : C

 
20.  
Which question will replace markup such as img=/smiley.png with <img src=”/smiley.png”>?

A. print preg_replace(‘/img=(\w+)/’, ‘<img src=”\1”>’, $text);

B. print preg_replace(‘/img=(\S+)/’, ‘<img src=”\1”>’, $text);

C. print preg_replace(‘/img=(\s+)/’, ‘<img src=”\1”>’, $text);

D. print preg_replace(‘/img=(\w)+/’, ‘<img src=”\1”>’, $text);


Answer : B
 


21.
Which of the following functions is most efficient for substituting fixed patterns in strings?

A. preg_replace()

B. str_replace()

C. str_ireplace()

D. substr_replace()


Answer : A
 

 
22.
What are the contents of output.txt after the following code snippet is run?

<?php
$str = ‘abcdefghijklmnop’;
$fp = fopen(“output.txt”, ‘w’);
for($i=0; $i< 4; $i++) {
fwrite($fp, $str, $i);
}

?>

A. abcd

B. aababcabcd

C. aababc

D. aaaa


Answer : C




23. Which of the following can be used to determine if a file is readable?

A. stat()

B. is_readable()

C. filetype()

D. fileowner()

E. finfo()


Answer : B




24.
If you have an open file resource, you can read data from it one line at a time with the _____ function. 
Answer : fgets()




25. Which of the following functions require an open file resource?

A. fgets()

B. fopen()

C. filemtime()

D. rewind()

E. reset()

Answer : B


26. Which of the following sentences are incorrect?
A. date() returns the current UNIX datestamp.

B. date() returns a formatted date string.

C. date() requires a time stamp to be passed to it.

D. date() returns a date array.


Answer : D

27. The ________ function will return the current UNIX time stamp.

Answer : time()



28. Which of the following functions will output the current time as 11:26 pm?
A. print date(‘H:m a’);

B. print date(‘G:M a’);

C. print date(‘G:i a’);

D. print strftime(‘%I:%M %p’);


Answer : C,D


29. Which of the following is not an aggregate function?
A. AVG

B. SUM

C. COUNT

D. GROUP BY

E. MIN


Answer : D

30. What is the default execution time set in set_time_limit()?

A.   20 secs

B.   30 secs

C.   40 secs
Answer : B

 
I hope this will help you and you will like it.

Don't forget to leave your comments.

Thank you
Ravinder

9 comments:

  1. Thanks ... nice collection...here is a list of interview questions and answers for 1,2 and 3 years experiance ...http://phpsollutions.blogspot.in/2014/07/php-interview-questions-and-answer-for.html

    ReplyDelete
  2. It was really a wonderful article and I was really impressed by reading this blog. We are giving all software Course Online Training. The HTML Training in Chennai is one of the reputed Training institute in Chennai. They give professional and real time training for all students.

    ReplyDelete
  3. Its nice collection......
    for more interview and answers http://askxpert.com/

    ReplyDelete
  4. Excellent collection of interview questions and answers. Thanks for reducing our efforts to search by providing them in a single blog.

    ReplyDelete

  5. Thanks for the sharing this blog is very intersting. It's very informarmative and very knowladgeable blog.

    Genesis Technologies having job vacancies for developers in Java. We are looking for talented people who are willing to work in a challenging environment.
    Now get the opportunity to work with us and acquire Java Developer Jobs in Indore.

    ReplyDelete
  6. Hi, thanks for sharing questions and answers its useful for prepare my interview php training courses

    ReplyDelete
  7. Thanks for the informative article. This is one of the best resources I have found in quite some time. Once Again Thanks for Sharing this Valuable Information i like this i Can Share this with My Friend Circle.
    PHP Interview Questions and Answer

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Really very informative and creative contents. This concept is a good way to enhance the knowledge.thanks for sharing. please

    keep it up
    PHP Training in Gurgaon

    ReplyDelete