PHP Interview Question Answer for Fresher

Most Important Interview Question Answer in PHP 


Q.1- What is PHP ?
Ans. The PHP  is the server side scripting  language that is used to develop attractive and   dynamic web application. It is  used for developing web based dynamic applications.

Q.2- PHP was  developed by whom and When?
Ans. PHP was developed by Rasmus Lerdorf  in 1994.

Q.3- What is the difference between PHP4 and PHP5?
Ans. PHP5 supports oops concept while PHP4 doesn’t support oops concepts. PHP5 error handling is better than PHP4’s error handling . PHP 5 shows function’s parameter hint while PHP 4 doesn’t show.

Q.4- What is the difference between echo and print
Ans. Echo and print both are the PHP statement that is used to display the output. Multiplie argument can pass separated by , in echo statement. But using print statement single argument can pass. Echo is faster than print statement. Print returns always true while echo doesn’t return any value.

Q.5- What is the difference between $var and $$var?
Ans. $var is a simple variable while $$var is known as reference variable. $var = “Aniket”; $$var = “is a PHPXperts”; $var is a simple PHP variable that we are used to. But the $$var is not very familiar like $var. It creates a variable name $Aniket with the value “is f PHPXperts.” Assigned . break it like this ${$var} => $Aniket .

Q.6- What are the differences between GET and POST methods.
Ans. Get is a unsecured method because it displays all the information in address-bar(url) while POST hides all the information so it is secure method. By default method is GET method. Get is the faster than POST method because get can carry limited amount of data while POST can carry unlimited data.

Q.7- What are the differences between require and include.
Ans. require and include both are used to include external PHP files. Require says a page must be developed, if a page is not developed yet then it shows fatal error that is the cause if script termination. While include says a page should be developed, if a page is not developed yet it shows warning error which doesn’t terminates your script.

Q.8- What are the different types of errors in PHP?
Ans. Three are three types of errors in php :
1. Notices: variable is undefined.
2. Warning: it is not critical error. it gives permission execute the script but shows warning message that means there is still a error.
3. Fatal : it is critical error because it stops the execution of the script.

Q.9- What is the difference between  unlink and unset function?
Ans. Unlink( ) function is used to delete the files while unset( ) function makes a variable undefined.

Q.11- How can we get the  properties  of browswer?
Ans. $_SERVER[‘HTTP_USER_AGENT’] global variable is used to get the browser properties.

Q.12- What is the maximum  filesize that can be uploaded in PHP and how can we increase it?
Ans. By default the maximum size of a file that can be uploaded is 2MB. you can change the maximum uploaded size value inside php.ini file set the value upload_max_filesize = 5M and restart all the services.

Q.13- How can we increase the execution time of  PHP ?
Ans. By default the maximum execution time of a PHP script is 30sec. If you want to change the following setup go inside php.ini file set max_execution_time = 40;

Q.14- How can we get the value of current session id?
Ans. The session_id( ) function is used to get the current session id. It returns the session id for the current session.

Q.15- How can we submit a html form without a submit button
Ans. The submit( ) function is used to submit form. first you have to get html form id through this document.getElementById(“formId”).submit() and then use submit( ) function. call this javascript function inside html body section at onclick=”your funciton name( )” events. set form action when you want to display the output, fetch the data on php and display your output.




How to print hello word in php

Now you are ready to write your fist php program. Open a new file in your preferred editor. Type

<html>
<head>
<title>My first PHP program</title>
</head>
<body>
<?php
print("Hello World<br/>\n");
phpinfo();
?>
</body>
</html>


PHP Server-Side or Client-Side ?

There are client-side methods and server-side methods to accomplish many tasks. When sending e-mail, for example, the client-side way is to open up the mail client software a preaddressed blank e-mail massage after the user clicks a MAILTO link. The server-side method is to make the user fill out a form, and the content are formatted as an email that  is sent via a simple Mail Transfer protocol (SMTP) server (which very well could be send machine that the server-side script is executing on). You can also choose between client method and server methods of browser-sniffing, from validation, drop-down lists, and arithmetic calculation, Sometimes you see subtle but meaningful differences in functionality (server-side drop-downs can be assembled dynamically, client-side cannot) but not always.
How to choose? know your audience. Server-side methods are generally a bit slower at runtime because of the extra transits they must make, but they don't assume anything about your visitor's browser capabilities and take less developer time to maintain.  

PHP Variable type

The main way to store information in the middle of a php program is by using a variable. Hear are the most important things to know about variable in php.

  1. All variable in php are denoted with a leading dollar sing ($).
  2. The value of the variable a value of its most recent assignment.
  3. Variable of assigned with the operator with the variable on the left hand side and the expression to be evaluated on the right.
  4. Variable can but do not read to be declare before assignment.
  5. Variable in php do not have intrinsic type - a variable dos not know in advance whether it will be used to stared a number of a string of characters.
  6. Variable use define they are assigned have default value.
  7. PHP does a good job of aromatically converting types from one to another when necessary.
  8. PHP  variable are perl-link' PHP has a total of eight data types which we use to construct our variables.
  • Integers : Are whole number without a decimal point like '123456' .
  • Doubles : Are Flouting point numbers like '3.14156.499'. 
  • Null : Is a special type that only has one value 'Null'.
  • Boolean : Have only two possible value other true or false 'True/False'. 
  • String : Are sequence of character like php support strings operators.
  • Array :  Are name and index collection of other value. 
  • Object : An object is a data type which store data and information 
  • Resource : The special resource type is not a actual data type. It is storing of a reference to function and resource external to php.

Basic knowledge of PHP language

  •  PHP Code :- For Partiality and Compatibility always use the long form.
          Long farm :         <?php    Expn     ?>
          Sort form  :         <?          Expn      ?>
         Sort form equivalent of <?    echo    ?>
         Note : No closing semicolon (;) is required <?     Expn      ?>

  • Semicolon (;) :- All statement must end in a semicolon (;) otherwise, errors will be generated. If the error doesn't make sense. You probably are missing a semicolon somewhere !
  • Single Quotations ('') :-  Single quotes content inside single quotes is evaluated literally.Therefore $ string actually means ( dollar sing ) string and does not represent the variables.
Example:
$string = ' single quoted ';
echo '$string';


  • Double Quotes ("") :- Double Quoted variable inside double quotes are evaluated for their value.
Example: 
$string=" double quoted ";
echo "$string";

  • Backslash ( Escape character ):- Escapes character that sold be evaluated literally when inside inside double quotation.
Example:  
$string= "double quoted";
echo "\$string is set as $string";
$string is set as double quotes.

  • Special characters :-  
Backslash (\)
Question mark (?)
Single Quotes (')
Double Quotes (")
Doller sing ($)

  • Comments :-  Single line for everything to the right of the double forward slashes.
// This is a comments.
Multiple line opening and closing tags.
/*        This is a comment      */  


  • Formatting Character :-
\n - New Line
\r - Carriage return
\t - Tab
\b - Back space


  • Define (name, value [$Boolean]):-
$Boolean - [optional] default: false, case-sensitive define a Constance a set value that is assigned globally making it variable to function and an argument.
Example:    
define('Hello', 'Hello word!' );
echo Hello;
Output: Hello word!

  • Function:- Function function name(argument) {},
function can be places only where in a page and will be available even with called above the actual function  being created as part of conditional statement has been evaluated.
Example: 
hello();
// Above the conditional statement this will cause an error 
if(0==0)
{
function hello()
{
echo 'Hello';
}
}

Fatal error: call to undefined function hell()
if(0==0)
{
function hello()
{
echo 'Hello ';
}
}

hello();
there();

function there()
{
echo 'there';
}


Hello there: function can have a argument (as above), argument passed to them, an default arguments with passed argument as optional. The argument names are use within that function as variable name.
Example:
function args($a,$b)
{
// has no default values request to input
echo "a=$a, b=$b";
}
args(1,2);
Output:
a=1,b=2


What is MySQL ?

MySQL (pronounced my Ess Q El) is a open source, SQL relational database management system (RDBMS) that is free for many users (more detail on that later). Early in its history, MySQL occasionally faced opposition because of its lack of support for sum core SQL constructs such as sub selects and foreign keys. Ultimately, however, MySQL found a broad, enthusiastic user base for its liberal licensing terms, perky performance, and ease of use. Its acceptance was aided in part by the wide variety of other technologies such as PHP, perl, Python, and the like that have encouraged its use through stable, well-documented modules and extensions.
Database are generally useful, perhaps the most consistently family of software products (the "killer Product") in modern computing. Like many computing products, both free and commercial, MySQL isn't a data base until you give it sum structure and form. You might think of this as the difference between a database and an RDBMS (that is, RDBMS plus user requirements equal a database).
There's lots more to say about MySQL, but then again, there's lots more space in which to say it.
 

What is php ?

PHP ( PHP : Hypertext Preprocessor ) is the open source, server-side, HTML-embedded web-scripting language that is compatible with all web servers (most notably Apache) PHP enables you to embed code fragments in normal HTML page - code that is interpreted as your pages are served up to users. PHP also serves as a glue language. making it easy to connect your web pages to server-side databases.



Python in AI: Getting Started with TensorFlow & PyTorch

  Artificial Intelligence (AI) is no longer just a buzzword. It powers recommendation systems, chatbots, self-driving cars, and more. At the...