Saturday, October 7, 2017

anil

Most important 35 PHP interview questions and answers for freshers


 I am an experienced PHP developer so here I am sharing my own personal interview experience. I had given around 40 interview's that time and I got selected in my last 5 interviews.

So in this article I am sharing 35 basic PHP programming interview questions with answers that will surely helpful for freshers to get a job. All questions are related to php, mysql, javascript, html, css and jquery.

Question #1 - What is PHP?


PHP is an open source server side scripting language mostly used for web applications. Its easy to learn compare to other programming language. PHP also a object oriented programming language like java, .net and c++.
Question #2 - What is the use of "echo" in php?


Mainly "echo" used to print a data on screen, for an Example: <?php echo 'This is my first website'; ?> , if we run it on browser, it will print the text on the screen.
Question #3 - How to include a file to a php page?


We include a file using "include('filepath.php') " or "require('filepath.php')" function with file path as its parameter.
Question #4 - What's the difference between include and require?


If the file is not found by require(), it will cause a fatal error and stop the execution of the script. If the file is not found by include(), a warning will be generate, but execution will continue.
Question #5 - require_once(), require(), include().What is difference between them?


require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.
Question #6 - Differences between GET and POST methods ?


We can only send 1024 bytes through GET method but by POST method can transfer large amount of data and POST is also a secure method than GET method .
Question #7 - How to declare an array in php?

we can declare array in PHP as below.
                     var $arr = array('apple', 'grape', 'lemon');
Question #8 - What is the use of 'print' in php?


Print commonly used to print text on screen like echo but print has a return type.  you can use with out parentheses with its argument list.
Example 
print('50 PHP Interview questions'); print 'Job Interview questions ');

Question #9 - What is use of count() function in php ?


count() function return total number of elements in an array or something in an object.
Question #10 - What is the difference between Session and Cookie?

Both are used to store user information on server. The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user's computers in the text file format. Cookies can't hold multiple variable while session can hold multiple variables..We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking
Question #11 - How to set cookies in PHP?


We can set cookies like Setcookie("user", "ram", time()+3600);
Question #12 - How to Retrieve a Cookie Value?


We can retrieve a cookie value like - echo $_COOKIE["user"];
Question #13 - How to create a session? How to set a value in session ? How to Remove data from a session?


Create session : session_start();
Set value into session : $_SESSION['USER_ID']=1;
Remove data from a session : unset($_SESSION['USER_ID'];
Question #14 - How to create a mysql connection?

we can create connection by using function mysql_connect(hostname,username,password,database);

Question #15 - How to select a database?


we can select database by using mysql_select_db($db_name); function and we can also select a database by using function mysql_query('use databaseName'); 
Question #16 - How to execute an sql query? How to fetch its result ?

$query = mysql_query("SELECT * FROM `employee` WHERE `u_id`='1'; ");
$result = mysql_fetch_array($query);
echo $result['phone_number'];
Question #17 - Write a program using while loop


$query = mysql_query("SELECT * FROM `employee` WHERE `u_id`='1'; ");
while($result = mysql_fetch_array($query))
{
echo $result['phone_number'.]."<br/>";
}
Question #18 - How we can retrieve the data in the result set of MySQL using PHP?


  • mysql_fetch_row()
  • mysql_fetch_array()
  • mysql_fetch_object()
  • mysql_fetch_assoc()

Question #19 - What is the use of explode() function ?


This function is used to split a string into an array. Syntax : array explode( string $delimiter , string $string [, int $limit ] ); 
Question #20 - What is the difference between explode() and split() functions?


Split function splits string into array by regular expression. Explode splits a string into array by string.
Both function are used to breaks a string into an array, the difference is that Split() function breaks split string into an array by regular expression and explode() splits a string into an array by string. explode() is faster than split() because it does not match the string based on regular expression.  
Question #21 - What is the use of mysql_real_escape_string() function?


mysql_real_escape_string() function mainly used to escapes special characters in a string for use in an SQL statement
Question #22 - Write down the code for save an uploaded file in php.


if ($_FILES["file"]["error"] == 0)
{
move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
Question #23 - How to create a text file in php?


$filename = "/home/user/guest/newfile.txt";
$file = fopen( $filename, "w" );
if( $file == false )
{
echo ( "Error in opening new file" ); exit();
}
fwrite( $file, "This is a simple test\n" );
fclose( $file );
Question #24 - How to strip whitespace (or other characters) from the beginning and end of a string ?


We can use trim() function to remove whitespaces or other predefined characters from both sides of a string.
Question #25 - What is the use of header() function in php ?


The header() function sends a raw HTTP header to a client browser.Remember that this function must be called before sending the actual out put.For example, You do not print any HTML element before using this function.
Question #26 - How to redirect a page in php?


we can redirect a page by using header("Location:index.php"); function.
Question #27 - How stop the execution of a php scrip ?


We mostly use exit() function to stop the execution of a page
Question #28 - How to set a page as a home page in a php based site ?


The default name of the home page is index.php in php based websites
Question #29 - How to find the length of a string?


we can use strlen() function to find the length of a string
Question #30 - what is the use of isset() in php?


isset() function is used to ensure if a variable is set and is not NULL
Question #31 - What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?


mysql_fetch_assoc() function Fetch data as an associative array, While mysql_fetch_array() fetches data as an associative array, a numeric array, or both
Question #32 - How to delete a file from the system


we can delete a file by using Unlink() function in php.
Question #33 - what is the difference between javascript and PHP ?

Commonly JavaScript known as Client side scripting language while PHP is a server side scripting language.
Question #34 - What is CSS?


CSS known as cascading Style Sheet. It is a best technique to style and present HTML.
Question #35 - What are the differences between ID and class in CSS? 

ID is used to identify one element , while a class is used to identify more than one element.


About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a huge information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :

Note: Only a member of this blog may post a comment.