Skip to main content

php interview questions and answers for two year experienced


php interview questions and answers for two year experienced

1Q:  What is the difference between the functions unlink and unset?

Ans: unlink() deletes the given file from the file system.
     unset() makes a variable undefined.

2Q:  How many ways we can pass the variable through the navigation
between the pages?

Ans: GET, QueryString, POST

3Q:  How can we know the count/number of elements of an array?

Ans:  2 ways
     a) sizeof($urarray) This function is an alias of count()
     b) count($urarray)

4Q:  How can we convert the time zones using PHP?

Ans: date_default_timezone_set('Asia/Tokyo');

5Q:  How many ways can we get the value of current session id?
Ans: session_id() returns the session id for the current session.

6Q:   How can we destroy the session, how can we unset the variable of
      a session?
Ans:  session_unregister — Unregister a global variable from the current
      session
      session_unset — Free all session variables.

7Q:   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

*8Q:   What is the difference between mysql_fetch_object and
      mysql_fetch_array?

Ans:
      mysql_fetch_object() is similar to mysql_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).


9Q:   What is meant by nl2br()?
Ans:  Inserts HTML line breaks (<BR />) before all newlines in a string.

10Q:  What is the functionality of the function strstr and stristr?

Ans:  strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.
      $email= 'test@gmail.com';
      $domain = strstr($email, '@');
      echo $domain; // prints @gmail.com
      here @ is the needle
      stristr is case-insensitive means able not able to diffrenciate between a and A

11Q:   Difference between get and post methods?
       Get Method:-
           1. Get method is faster then post.
           2. Get method is not secure.
           3. Get method is transfer the data through url.
           4. GET method is restricted to send upto 1024 characters only.
           5. GET method can't be used to send images or word documents, to the server.

       Post Method:-

          1. Post method is secure
          2. post method is transfer the data through headers.
          3. we can transfer unlimited data. ans its a secure.

12Q:  Who is the father of PHP?

Ans:  The father of php is Rasmus Lerdorf

13Q:  what is the difference between $sno and $$sno

Ans:    $name is variable where as $$name is reference variable
like $name=sonia and $$name=singh so $sonia value is singh.

14Q: How can i destroy the cookie?

Ans: In php manual, you can delete a cookie by setting a expiration date is in the past:
     setcookie("key","",time()-3600);

15Q: Different type of errors in PHP?

Ans:  in PHP there are 4 types of errors.
    1. NOTICE
    2. WARNING
    3. FATAL ERROR
16Q: Difference between include and include_once?

Ans: include:  using this include function the file path include directorys and it's sub directorys.
     include_once:

17Q: Difference between include and require

Ans: Both include and require used to include a file. but when included file not found
     Include send Warning where as Require send Fatal Error .

18Q: How can we submit a form with out submit button?

Ans: Java script submit() function is used for submit form without submit button
     on click call document.formname.submit()

19Q:  What does a special set of tags <?= and ?> do in PHP?

Ans: The output is displayed directly to the browser.

20Q: How do you define a constant?

Ans: Via define() directive, like define ("MYCONSTANT", 100);

21Q: How do you pass a variable by value?

Ans:

<?php
    function add_some_extra(&$string)
 {
     $string .= 'and something extra.';
 }
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, and something extra.'
?>
22Q: How can i display variable with value and datatype?

Ans: var_dump (); using to display the display variable with value and data type.

23Q: How can i check whether the variable is set with value or not?

Ans: isset() function to check where the variable is set are not.

24Q: How can i remove the variable value?
Ans: If a globalized variable is unset() inside of a function, only the local variable is destroyed.

25Q: I want to combine two variables together:
Ans:    $var1 = 'Welcome to ';
        $var2 = 'Zend Technologies';
        $var3= $var1.$var2;
What will work faster? Code sample 1:
$var 3 = $var1.$var2;
Or code sample 2:
$var3 = "$var1$var2";

26Q: What are the print functions we have in php?

Ans: echo ;
print();
var_dump();
27Q:  How can i destroy the sessions?
Ans:  session_destroy(); function to use destroy the session.

28Q:  Function to move the uploaded file from one location to another location?
Ans:  move_uploaded_file

29Q: How can i find out the IP address of client?
Ans: $_SERVER(REMOTE_ADD);

30Q: difference between mysql_fetch_row and mysql_fetch_object
Ans: mysql_fetch_row is used to fetch the single row only.
     mysql_fetch_object use this function to get all records of the table.

31Q: How can we create a database using PHP and mysql?

Ans: "CREATE DATABASE NAME"

We can create MySQL database with the use of
mysql_create_db("Database Name")

32Q: What is the difference between echo and print statement?

Ans: echo  not returns the any values.
print returns the values

33Q:  What is the difference between explode and split?

Ans:  split() and explode() both are php function used to explode a string. split() almost was used in older php version and now availble version of php is higher than

ten and its also support explode().

34Q: difference between mysql_connect and mysql_pconnect

Ans:  mysql_pconnect()
isd to make a persistent connection to the database which means a SQL link that do not close when the execution of your script ends.

35Q: what is the syntax of mail function.

Ans: mail();

36Q: What is the default port number of web server?

Ans: 8080

37Q: Is PHP compiled or Interpreted language

Ans: php interpreted language.

38Q: Is php supports multiple Databases

Ans: yes

39Q: PHP stands for?

Ans: hyper text pre processer

40Q: Which function used to get the current time in mysql?
Ans: getTime()

41Q:  To remove duplicate rows from the result set of a SELECT use the following keyword:

Ans: DISTINCT

42Q:   What are default session time and path?
Ans:   default session time in PHP is 1440 seconds or 24 minutes
       Default session save path id temporary folder /tmp

43Q:  how to track no of user logged in ?
Ans:  whenever a user logs in track the IP, userID etc..and store it in a DB with a active flag while log out or sesion expire make it inactive. At any time by    

counting the no: of active records we can get the no: of visitors.

44Q: what is difference between explode implode?

Ans: explode function:-it breaks a string into array.
<?php
$str="hello world.it's a beautiful day.":
print_r(explode(" ",$str):// space between two double quotes should be there otherwise it shows Warning: explode() [function.explode]: Empty delimiter in D:\www

\vhosts\localhost\test\setupTest.php on line 29
?>
ans-ARRAY
[0]=>hello
[1]=>world.
[2]=>it's
[3]=>a
[4]=>beautiful
[5]=>day.

implode:-returns a string from elements of an array.
<?php
$arr=array('hello','world!',beautiful,'day!');
echo implode(" ",$arr);
?>
ans-hello world! beautiful day!


45Q: Will comparison of string "10" and integer 11 work in PHP?

Ans: Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.

46Q: what is terinary opertion in php?

ans- It is called the ternary operator because it takes three operands - a condition, a result for true, and a result for false.

                    OR

Expression preceding the ? is evaluated, if it’s true, then the expression preceding    the : is executed, otherwise, the expression following : is executed.

    <?php
            $agestr = ($age < 18) ? 'child' : 'adult';
    ?>

47Q: explain two types of arraay sort.

Ans: sort()->sort the array value alphabetically, but not maintaining the index.
    asort()->sort the array value alphabetically, and also maintaining the index.
    arsort()->sort the array value alphabetically in reverse order and also maintaining the index.

    ksort()->sort the array according to key.
    krsort()->sort the array according to key in the reverse order.

48Q: how can u know size of array?

Ans: The sizeof() function counts the elements of an array, or the properties of an object.

This function is an alias of the count() function.
$a = array(1,2,2,
    array(1,1));
    echo sizeof($a);// 4
    echo sizeof($a[1]);// 1
        echo sizeof($a[3]);// 2

49Q: Number of argument in a function,How can u know?

Ans: func_num_args() function returns the number of parameters passed in.

50Q: how can u get current date and time?

Ans: date('r');

51Q: How can u et ip address of asystem?

Ans:  $_SERVER['SERVER_ADDR'];

     $_SERVER['REMOTE_ADDR'];

52Q: What is Isset()?

Ans: isset() determines whether a certain variable has already been declared by PHP. It returns a boolean value true if the variable has already been set, and false

otherwise, or if the variable is set to the value NULL.

53Q: what is difference between __sleep and __wakeup()?

Ans:  __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

54Q: How many way you can get a date from mysql?

ans: SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();

55Q: what are the joins in mysql and what are they?

Ans: Different types of joins are ----

    1.JOIN(Inner Join): Return rows when there is at least one match in both tables
    2.LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
    3.RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
    4.FULL JOIN: Return rows when there is a match in one of the tables

56Q: what is normalisation ?

Ans: The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the

previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).

   First Normal Form
The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row,

       and that every column stores the least amount of information possible (making the field atomic).

  Second Normal Form
Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical

columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.

   Third Normal Form

I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on

the primary key, but dependant on another value in the table

57Q: What is the maximum length of a table name, a database name, or a field name in MySQL?

Ans: Database name: 64 characters
     Table name: 64 characters
     Column name: 64 characters

58Q: list of php CMS?
                             
Ans: Drupal, Joomla, PhpBB, Wordpress.

59Q: list of frameworks in php ?

Ans: Zend,CodeIgniter and CackePHP framework.

60Q: Difference between CMS and Framework.

Ans: An application framework is something which we use to build our web application on, I mean we use the framework provided classes, events, methods and create an  

  application.

     A CMS is already a developed application with a set of features, however most of them are coded in such a way that users can tweak them around and modify the code

     to fit their own needs.

      So a framework does not come with a working application, but a CMS comes with one.

61Q: Http is stateless or stateful?

Ans: stateless.

62Q:  Max execution time?

Ans: 30sec.

63Q: Max uploading size?

Ans: 2Mb

64Q: How session starts?

Ans: session_start()









Popular posts from this blog

insert document in collection mongodb

 Insert document in collection Two types of insert Insert single records:  Insert multiple records Insert single records:    syntax:  db.collection.insertOne(    <document>,    {       writeConcern: <document>    } ) Example 1:  db.users.insertOne({"name":"ram","email":"ram@gmail.com"})  Example 2:  db.users.insertOne( [{"employee":{"name":"ram","email":"ram@gmail.com"}}] ) Insert multiple records:   syntax : db.Collection_name.insertMany( [<document 1>, <document 2>, …], {     writeConcern: <document>,     ordered: <boolean> }) Example:  db.users.insertMany([{"name":"ram","email":"ram@gmail.com"},{"name":"raju","email":"raju@gmail.com"}])

Collection Shell Commands in MongoDB

Create Collection  Syntax: db.createCollection("Collection Name"); Example: db.createCollection("users"); Delete collection in Mongodb Shell Command db.collection.drop()  Find Collection in Mongodb Shell Command db.collection.find() Show all Collection in Mongodb Shell Command show collections Creat Collection in Mongodb Shell Command db.createCollection("users") Rename the Collection In Mongodb Shell Command db.collection.renameCollection()   Update the single document in MongoDB collections Shell Command db.collection.updateOne()  Updates all the documents in MongoDB collections that match the given query.  db.collection.updateMany() Replaces the first matching document in MongoDB collection db.collection.replaceOne()  Deletes the first document in Mongodb collection db.collection.deleteOne()  db.collection.deleteMany()