Tolal:94 Click:
1
2 3 4 5
PHP Interview Questions And Answers
Page 1
Ques: 1 What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?
Ans:
GET Method:
Using get method we can able to pass 2K data from HTML.All data we are passing to Server will be displayed on the Browser. This is used to sent small size data.
POST Method:
1n this method we does not have any size limitation. All data passed to server will be hidden, User cannot able to see this info on the browser.The data is send into a small packets. This used to sent large amount of data.
Ques: 2 What is PHP?
Ans:
PHP(PHP:Hypertext Preprocessor) is a server-side programing languages.It is use to made the web pages dynamically.
PHP is introduce by Rasmus Lerdorf in 1995.It is a free released and open source softwareWe introduce PHP under the HTML tags.In this scripts are executed on server side.It supports many database like that MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.
Ques: 3 Tell more about PHP file?
Ans:
In PHP file we may contain text, HTML tags and scripts.It returned to the browser in form of plain HTML code.We can save PHP file using these three extension .php,.php3 or .phtml. An Example of PHP file are given below:
<html>
<head><title>PHPExample</title></head>
<body>
<h1><?php echo "Welcome in PHP world"; ?></h1>
<?php
$txt = "This is my first PHP script";
/* statement */
echo $txt;
?>
</body>
</html>
Ques: 4 How PHP is more secure than JavaScript?
Ans:
We use PHP in a HTML with in some specific tags.It is much secure than JavaScript because of when client process the PHP page than PHP code only send the output of given request without PHP source code.So, the PHP code Can not steal by non-authorized person.Where in the case of JavaScript It also send the source of JavaScript to the client with output.
Ques: 5 What do you understand about MySQL?
Ans:
MySQL is an open source Relational Database Management System(RDMS).It sound as /maɪˌɛskjuːˈɛl/ ("My ess cue el").It is introduce in 23May,1995 by MySQLAB,its an Swedish company.Now,is a subsidiary of Sun Microsystems,.MySQL is designed in C and C++.We can download is codes as per rules of GNU(General Public Licence).
It fast,reliable and flexible.It works on many platforms like:Uinux,Linux and Windows.
Ques: 6 Why we used PHP?
Ans:
Because of several main reason we have to use PHP. These are:
1.PHP runs on many different platforms like that Unix,Linux and Windows etc.
2.It codes and software are free and easy to download.
3.It is secure because user can only aware about output doesn't know how that comes.
4.It is fast,flexible and reliable.
5.It supports many servers like: Apache,IIS etc.
Ques: 7 How to install PHP in our system?
Ans:
First you have download PHP software from: http://www.php.net/downloads.php
than you have to install Database Which you want to use:Like MySQL download from:
http://www.mysql.com/downloads/index.html
than download server on which you want to work.from:
http://httpd.apache.org/download.cgi
After install them you will ready to work on PHP.
Ques: 8 What is the Syntax of PHP?
Ans:
Below I will given you how PHP work with HTML codes.Always keep that in mind PHP starts with <?php and close with ?>Their in not a specific place of this block in the HTML code.Like that,<?php/*Enter your code*/?>Now, I have given you a example on PHP. Like that you can create your first PHP file.<html><body><?phpecho \"Welcome in world of PHP.\";?></body></html> Keep one thing in mind when we write PHP code each PHP line should ends with semicolon(;).
Ques: 9 Tell me about basic statements that we used in PHP?
Ans:
PHP has two basic statements.These are echo and print.I have given you a example say how to use echo and print in PHP.
Example:
<html>
<title>This is my first PHP page</title>
<body>
<?php
echo "Welcome!";
?>
</body>
</html>
////
<html>
</body>
<?php
$decimal_number = 109.09;
printf("%.2f", $decimal_number);
?>
</body>
</html>
Ques: 10 What are the PHP variables?
Ans:
We use Variables to store the values,Like: Strings, Numbers or Array.In PHP their s no limit to create number of variables.All variable in PHP starts with dollar("$")sign and we assign value to the variable using "=" operator.
Syntax:
$variable_name = vale;
Example:
<?php
$Name = "Abhi";
$Age = 23;
Ques: 11 What are the Limitations of Variable Naming?
Ans:
Some main limitations of Variable Naming in PHP are given below:
1.In PHP their is not a fixed limit for Variable Name as compare to other programing language.
2.First letter of PHP Variable must start with a letters,numbers or underscore "_".
3.Variable Name should be a combination of Alpha-Numeric Characters or underscores(a-z,A-Z,0-9or_)
4.Variable name must be one word.If their is more than one word in our Variable Name.Than we can distinguish them with underscore("_").Like $first_name.
Ques: 12 How to declare data types in PHP?
Ans:
Data type that we used in PHP are given below:
1.Numeric data type
2.Array data type
3.String data type
1.Numeric data type: We introduce numeric data type when we use numbers in PHP.Two different types of numeric data types are integer and double.
integer data type use to introduce the whole number.Where as double data type use to introduce float values.
Example:
$intnum = 50;
$doublepercentage = 67.9;
2.Array data type: In this we store many values in a single variable.In this we show all values of variable with their variable and index.
Example:
$arrayMarks[0] = 70;
$arrayMarks[1] = 75;
$arrayMarks[2] = 65;
$intTotalMark = $arrayMarks[0] + $arrayMarks[1] + $arrayMarks[2];
echo $intTotalMark;
Output: 210
3.String data type:In this values of variables may be of combination of characters and numbers or words.
Examle:
$stringName = "Abhi";
$stringId = "Abhi007";
String Concatenation:In thois we can add two strings using "."operator.When we add two strings second string add at the end of first string.
Example:
$stringFirst_Name = "vivek";
$stringSpace = " ";
$stringLast_Name = "agarwal";
$stringName = $stringFirst_Name.$stringSpace.$stringLast_Name;
echo $stringName;
Output: vivek agarwal
Ques: 13 What is the use of strlen() and strpos() functions?
Ans:
strlen() function is used to find out the length of the given string.
Example:
<?php
echo strlen("R4R Welcomes you!");
?>
output: 17
strpos() function is used to match a character or word from the given string.And return the position of the character or word.
Example:This program return the position of 'you'.
<?php
echo strpos("R4R Welcomes you","you");
?>
output: 13
Correct answer is 13 not 14.Because in strpos() function counting starts with 0 not 1.
Ques: 14 Tell me about PHP operator?
Ans:
PHP provide us many operator. These are:
1.Arithmetic Operator
2.Assignment Operator
3.Comparison Operator
4.logical Operator
1.Arithmetic Operator:Some arithmetic operators are given below,
Addition('+') m+4 , 8(given m=4)
Subtraction('-') m-4, 4(given m=8)
Multiplication('*') m*4, 8(given m=2)
Division('/') m/4, 2(given m=8)
Modulus (division remainder)('%') m%2, 1(given m=3)
Increment('++') m++, m=5(given m=4)
Decrement('--') m--, m=6(given m=5)
2.Assignment Operator: Some assignment operations are given below,
= m=n
-= m-=n or m=m-n
*= m*=n or m=m*n
/= m/=n or m=m/n
.= m.=n or m=m.n
%= m%=n or m=m%n
+= m+=n or m=m+n
3.Comparison Operator:Some comparison operators are given below,
==(is equal to) 2==5returns false
!=(is not equal to) 2==5returns true
>(is greater than) 2==5returns false
<(is less than) 2==5returns true
>=(greater than or equal to) 2==5returns false
<=(is less than or equal to) 2==5returns true
4.Logical Operators:Some logic operators are given below:
&&(and) (m<4 && n>2)returns true(given m=3,n=5)
||(or) (m=4 && n=4)returns false(given m=5,n=6)
!(not) !(m==n)returns true(given m=2,n=3)
Ques: 15 How we use if..else and elseif statement in PHP?
Ans:
If..else statement is used where we want to execute some code if condition is true otherwise execute some other code.
Syntax:
if (condition)
code to be executed;//when condition is true
else
code to be executed;//When condition is false
Example:
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Weekend!";
else
echo "Today!";
?>
</body>
</html>
Elseif statement is used where we want to execute some code if multiple conditions are true.
Syntax:
if (condition)
code to be executed;//condition is true
elseif (condition)
code to be executed;//condition is true
else
code to be executed;//condition is false
Example:
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Weekend!";
elseif ($d=="Sun")
echo "Sunday!";
else
echo "Today!";
?>
</body>
</html>
Ques: 16 How to use Switch statement in PHP?
Ans:
If you want to execute more than one code than we use Switch statement.
Syntax:
switch (expression)
{
case label1:
code to be executed if expression = label1;
break;
case label2:
code to be executed if expression = label2;
break;
default:
code to be executed
if expression is different
from both label1 and label2;
}
In this One expression is execute one time.We match a particular value.If it is matched than its correspondent case will executed.When break comes executed case will stopped and command go on next case.If none of the case are executed than default case will executed.
Example:
<html>
<body>
<?php
switch ($m)
{
case 1:
echo "Number One";
break;
case 2:
echo "Number Two";
break;
case 3:
echo "Number Three";
break;
default:
echo "No number between One and Three";
}
?>
</body>
</html>
Ques: 17 What do you understand array in PHP?
Ans:
We create array in PHP to solved out the problem of writing same variable name many time.In this we create a array of variable name and enter the similar variables in terms of element.Each element in array has a unique key.Using that key we can easily access the wanted element.Arrays are essential for storing, managing and operating on sets of variables effectively. Array are of three types:
1.Numeric array
2.Associative array
3.Multidimensional array
Numeric array is used to create an array with a unique key.Associative array is used to create an array where each unique key is associated with their value.Multidimensional array is used when we declare multiple arrays in an array.
Ques: 18 What do you understand about Numeric array, Associative array and Multidimensional array?
Ans:
Here, I explain Numeric array, Associative array and Multidimensional array in detail:
1. Numeric array:In this array we entered each array element with a unique key.Below I have given you examples how to use Numeric Arrays in PHP.
Example:
<?php
$p_names = array("vivek","abhi","ankit","nik");
echo $p_names[0] . " ," . $p_names[1] . " . $p_names[2] . " and " . $p_names[3] . " are friends";
?>
'OR'
<?php
$names[0] = "vivek";
$names[1] = "abhi";
$names[2] = "ankit";
$names[3] = "nik";
echo $p_names[0] . " ," . $p_names[1] . " . $p_names[2] . " and " . $p_names[3] . " are friends";
?>
2.Associative array:In this array we assign array elements with unique key and their respected values.Below I have given you examples how to use Associative Arrays in PHP.
Example:
<?php
$marks['vivek'] = "90";
$marks['abhi'] = "80";
$marks['ankit'] = "85";
echo "vivek scored" . $marks['vivek'] . " percent in CAT exam.";
?>
Output:
vivek scored 90 percent in CAT exam.
3.Multidimensional array:In this array we can declare array with in an array.
In this multiple arrays has a automatically assign unique key.Below I have given you examples how to use Multidimensional Arrays in PHP.
Example:
<?php
$families = array
(
"Agarwal"=>array
(
"vivek",
"vineet",
"abhi"
),
"Patel"=>array
(
"hariom"
),
"Singh"=>array
(
"saurabh",
"ram",
"rohan"
)
);
echo "Is " . $families['Agarwal'][0] .
" belongs to the Agarwal family?";
?>
Output:
Is vivek belongs to the Agarwal family?
Ques: 19 What do you understand about looping in PHP?
Ans:
Looping uses, when we want to execute some block of code for a specific time.In PHP Looping are of Four types:
1.while
2.do..while
3.for
4.foreach
We uses 'while', when we want to execute a block of code till given condition is true.
We uses 'do..while', when we want to execute a block of code at least one.After that it checks the condition if it is true than block of code is execute till condition is true,Other wise stopped the execution.
We uses 'for', when we want to execute a block of code many times.
We uses 'foreach', when we want to execute a block of code for each element in an array.
Ques: 20 How to use while,do..while,for and foreach loop in PHP?
Ans:
Below I have given u how to use while, do.while, for and foreach loop in PHP.
1.while:Uses, we want to execute a line of code many times till specific condition is true.
Syntax:
while (condition)
code will be executed;//When condition is true
Example:
<html>
<body>
<?php
$m=3;
while($3<=6)
{
echo "Number is " . $m . "<br />";
$m++;
}
?>
</body>
</html>
2.do..while:Uses, we want to execute a block of code at least one time. After that it checks the condition, till its correct the block of code will executed.Otherwise stopped the execution.
Syntax:
do
{
code will be executed;
}
while (condition);//loop execute atleast one time whenever condition is true or false
Example:
<html>
<body>
<?php
$m=2;
do
{
$m++;
echo "Number is " . $m . "<br />";
}
while ($m<7);
?>
</body>
</html>
3.for:Uses, When we want execute a block of code for some specific times.
Syntax:
for (initialize; condition; increment/decrement)
{
code will be executed;
}
Example:
<html>
<body>
<?php
for ($m=2; $m<=4; $m++)
{
echo "R4R Welcomes You!<br />";
}
?>
</body>
</html>
4.foreach:Uses, When When we want execute a block of code for each element in an array.
Syntax:
foreach (array as value)
{
code will be executed;
}
Example:
<html>
<body>
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
}
?>
</body>
</html>
Goto Page:
1
2 3 4 5
PHP Objective
PHP Objective Questions And Answers
PHP Interview Questions And Answers
PHP Interview Questions And Answers
R4R,PHP Objective, PHP Subjective, PHP Interview Questions And Answers,PHP,PHP Interview,PHP Questions ,PHP Answers