Wednesday, March 6, 2013

PHP interview questions for 1 year experience


PHP
We should start with the inventor of PHP.

Q. Who is the father of PHP ?
A. Rasmus Lerdorf is known as the father of PHP.

Q. How can we submit a form without a submit button?
A. We can use javascript submit() function to submit the form without clicking on submit button. You can use the document.formname.submit() method to onclick, onchange events to perform the form submission. You can even set a timer where you can automatically submit the form after some time.

Q. PHP configuration file.
A. php.ini

Q. Differences between GET and POST methods
A. 1) When we use GET method the requested data show in URL while in POST method doesn't, So    POST is good to send the sensitive data.
     2) Also in GET method you can send the limited data(2kb) but in POST it is 8 MB default.Also you can increase the POST data size through php.ini file.

Q. Difference b/w ''(single quotes) and ""(Double quotes) ?
A. '' is used for string. "" evaluates the string.
   Example :
   <?php 
    $a = 'abc'; 
    echo $b = 'hello $a'; // hello $a
    echo '<br>';
    echo $c = "hello $a"; // hello abc
   ?>

Q.What is the difference between $name and $$name?
A. $$name is called dynamic variable.For example.$name = “Santosh”;$$name = “is a moderator of this blog.”;$name is a simple PHP variable. But the $$name creates a variable name $Santosh and this value is “is a moderator of this blog.” assigned. break it like this ${$name} => $Santosh. That is, a variable name which can be set and used dynamically.

Q. What are the differences between include and require?
A. Both include and require used to include a file but when included file not found, "include" send warning where as "require" send Fatal error .

Q. What does the strpos function in php ?
A. It return the index number if search string is found. Point to be noticed that it return false if string
is not found. Many developers confuses with its return type.

Also if you know any function in php then also remember the return data type also.

Q. Does php support data type ?
A. No. (Example:  $a = 5;  PHP automatic understand that $a is integer type variable , we don't need to mention it as int $a =5; )

Q. Difference b/w = (Equal to), ==(Double equal to), ===(triple equal to) ?
A.  = (Equal to) is a assignment operator , Ex. ($a=5).
      == (Double equal to) is a conditional operator , Ex. if($a==5) {echo 'Hi';}
     ===(triple equal to) is also a conditional operator which match the datatype also.
    Ex.  :  $a='5'; // Hera $a is string
              if($a===5) { // here === check the value as well as the datatype 
                echo 'matched';
              }
              else {
                echo 'Not matched';

             }
 Output : Not matched

FEEL FREE TO ASK THE QUESTIONS.

Continue...........

3 comments:

  1. nice questions ... please go threw this for more question and answers
    ... http://phpsollutions.blogspot.com/2014/07/php-interview-questions-and-answer-for.html

    ReplyDelete
  2. if($a===5) { // here === check the value as well as the datatype
    echo 'matched';
    }
    else {
    echo 'Not matched';

    }
    please explain it , how this statement checking data type thanks.

    ReplyDelete
    Replies
    1. Actually === is an Identical operator which match the value as well as the type of the value. In the above example $a='5' which is a string but in if condition it is check with the 5 which is a number , so it will not match and goes to the else condition.

      Thanx

      Delete