Tolal:94 Click:
1
2 3 4 5
PHP Interview Questions And Answers
Page 1
Ques: 1 how can we connect more than one database into webpage..
Ques: 2 PHP means?
uses of PHP?
types of PHP?
explain PHP?
Ques: 3 How session will work when we disable cookies of client browser?
Ans:
Session is kind of cookie who is work on server side.For working of session on server side cookies should be enable on server side and also on client side browser.
But session will also work when cookies are disable on client side by using URL session passing.
Ques: 4 How we use array_search() in PHP?
Ans:
When we use array_search() function if it found the particular value than it will return index corresponding to array value.
Example:
<?php
$Emp_name_array = array(0 => 'vivek', 1 => 'umang', 2 => 'shrish', 3 => 'jalees');
$key = array_search('umang', $Emp_name_array);
// return $key = 1;
$key = array_search('vivek', $Emp_name_array); // return $key = 0;
?>
Ques: 5 How you differentiate among sort(),assort() and Ksort()?
Ans:
1) sort()
This function sorts an array. Elements will be arranged
from lowest to highest when this function has completed.
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
----------------------------OUTPUT---------------------
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
-------------------------------------------------------
2) asort()
This function sorts an array such that array indices
maintain their correlation with the array elements they are
associated with. This is used mainly when sorting
associative arrays where the actual element order is
significant.
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" =>
"banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
--------------------OUTPUT------------------------
c = apple
b = banana
d = lemon
a = orange
--------------------------------------------------
3) ksort()
Sorts an array by key, maintaining key to data
correlations. This is useful mainly for associative arrays.
<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana",
"c"=>"apple");
ksort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
--------------------OUTPUT----------------------------
a = orange
b = banana
c = apple
d = lemon
------------------------------------------------------
Ans:
The sort() function sort the array. Element will arranged in lowest to highest when function has completed.
The assort() function sort the associative arrays and where the actual element order is
significant.
The Ksort() function sort an array by key. This is useful for associative array.
Ans:
Sort-sorting arry
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
Assort-Sort an array and maintain index association
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
The above example will output:
c = apple
b = banana
d = lemon
a = orange
ksort — Sort an array by key
<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
ksort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
The above example will output:
a = orange
b = banana
c = apple
d = lemon
Ans:
Sort-sorting arry
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
Assort-Sort an array and maintain index association
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
The above example will output:
c = apple
b = banana
d = lemon
a = orange
ksort — Sort an array by key
<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
ksort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
The above example will output:
a = orange
b = banana
c = apple
d = lemon
Ans:
sort() -> sorting the value in ascending.d
assort() -> sorting only the value.
Example: $x=array([0]=>32,[1]=>11,[2]=>10)
print_r(asort($x); means: [2]=>10,[1]=>11,[0]=>32
Ksort() -> Sorting only key not value
Ans:
In array we can get both key value and array value.key is refer for index,array is what we are storing.sort() use to sort in ascendending array value.arsort() user array in reverse order.
ksort means key valuesare arranged in ascending order
Ans:
sort() will order the array by its values without preserving the keys. Use it when array is indexed numerically or when you do not care about the keys.
asort() will also sort the array by its values, but it will preserve the key -> value association.
The ksort() function sorts an array by the keys. The values keep their original keys.
This function returns TRUE on success, or FALSE on failure.
Ans:
The sort() function sorts an array by the values.
This function assigns new keys for the elements in the array. Existing keys will be removed.
This function returns TRUE on success, or FALSE on failure.
The asort() function sorts an array by the values. The values keep their original keys.
This function returns TRUE on success, or FALSE on failure.
The ksort() function sorts an array by the keys. The values keep their original keys.
This function returns TRUE on success, or FALSE on failure.
Ans:
bool sort ( array &$array [, int $sort_flags] )
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
Returns TRUE on success or FALSE on failure.
Example 329. sort() example
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
Ans:
bool sort ( array &$array [, int $sort_flags] )
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
Returns TRUE on success or FALSE on failure.
Example 329. sort() example
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
Ans:
sort()
void sort(array target_array [, int sort_flags])
The sort() function sorts the target_array, ordering elements from lowest to highest value.
Note that it doesn’t return the sorted array. Instead, it sorts the array “in place,” returning
nothing, regardless of outcome. The optional sort_flags parameter modifies the function’s
default behavior in accordance with its assigned value:
• SORT_NUMERIC: Sort items numerically. This is useful when sorting integers or floats.
• SORT_REGULAR: Sort items by their ASCII value. This means that B will come before a, for
instance. A quick search online will produce several ASCII tables.
• SORT_STRING: Sort items in a fashion that might better correspond with how a human
might perceive the correct order. See natsort() for further information about this matter,
introduced later in this section.
Consider an example. Suppose you wanted to sort exam grades from lowest to highest:
$grades = array(42,57,98,100,100,43,78,12);
sort($grades);
print_r($grades);
The outcome looks like this:
Array ( [0] => 12 [1] => 42 [2] => 43 [3] => 57 [4] => 78 [5] => 98
[6] => 100 [7] => 100 )
It’s important to note that key/value associations are not maintained. Consider the
following example:
$states = array("OH" => "Ohio", "CA" => "California", "MD" => "Maryland");
sort($states);
print_r($states);
Here’s the output:
Array ( [0] => California [1] => Maryland [2] => Ohio )
Ans:
sort destroy key association asort keeps key association of values. ksost sort the key value only
Ques: 6 How to print \ in php with out using . or *?.
Ans:
I have given you a example which definitely solved your query.
Example:
<?php
print "\\";
?>
output:
\\
Ans:
<?php
echo "\\";
?>
Ans:
\ for slah and * for adding values
Ques: 7 Why is PHP-MySQL used for web Development?
Ans:
We use PHP-MySQL in web development because both are open source means both free to use. Both when MySQL work with PHP it gives result much faster than when MySQL work with Java/.Net/Jsp.
Ques: 8 What function we used to change timezone from one to another ?
Ans:
I have given you a function using them we can change a timezone into another timezone.
date_default_timezone_set() function
Example:
date_default_timezone_set('India');
And we use date_default_timezone_get() function to get the entered date.
Ques: 9 How do you understand about stored procedure,Triggers and transaction in php?
Ans:
Below I have given how stored procedure,Triggers and transaction work in PHP:
1.Stored Procedure: It is combination of some SQL commands it is stored and can be compiled.Suppose that when user is executed a command than user has don't need to reissue the entire query he can use the stored procedure.Basically main reason to use the stored procedure is that using this we can decrease the time of reissue of that query. Because work done on server side is more than the work done on application side.
2.Trigger: Trigger is a stored procedure.This is used to work stored procedure effectively.It is invoked when a special type of event comes.For effectively understand this i have given you a example.
When we attach a trigger with stored procedure than when we delete a record from transaction table than will automatically work and delete the respective client from client table.
3.Transaction: Transaction is that in which particular amount of data goes from the a client to the another client.We maintain the transaction record into a table called transaction table.
Ques: 10 How we can upload videos using PHP?
Ans:
When want to upload videos using PHP we should follow these steps:
1.first you have to encrypt the the file which you want to upload by using "multipart-form-data" to get the $_FILES in the form submition.
2.After getting the $_FILES['tmp_name'] in the submition
3.By using move_uploaded_file (tmp_location,destination) function in PHP we can move the file from original location.
Ques: 11 How can we create a database using PHP and myqsl?
Ans:
I have given you a example using this you can create a database.
<?php
$con =mysql_connect("localhost","vivek","vivabh");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database has been created";
}
else
{
echo "Error to create database: " . mysql_error();
}
mysql_close($con);
?>
Ques: 12 What do you understand about Joomala in PHP?
Ans:
Joomala is an content management system who is programmed with PHP.Using this we can modified the PHP sit with their content easily.
Ques: 13 How you can differentiate abstract class and interface?
Ans:
There are some main difference between abstract and interface are given below:
1.In an abstract we can use sharable code where in the case of interface their is no facility to use sharable code.
2.In which class we implement an interface class. All method that we use should be defined in interface. Where as class those extending an abstract while a class extending an abstract class their is no need to defined methods
in the abstract class.
Ques: 14 What do you understand about Implode and Explode functions?
Ans:
The main difference b/w Implode and Explode functions is that We use Implode function to convert the array element into string where each value of array is separated by coma(,).
Example:
<?php
$array = array('First_Name', 'Email_Id', 'Phone_NO');
$comma_separated_string = implode(",", $array);
echo $comma_separated_string;
?>
output:
First_Name,Email_Id,Phone_No
We use Explode function to convert the string value those are separated with coma(,) into array.
Example:
<?php
$comma_separated_string = string('First_Name,Email_Id,Phone_No');
$array = Explode(",", $coma_separated_string);
echo $array;
?>
output:
First_Name
Email_Id
Phone_No
Ques: 15 Can we submit a form without submit button?
Ans:
Using JavaScript we can submit a form without submit button.
Example:
document.FORM_NAME.action="Welcome.php";
document.FORM_NAME.submit();//this is used to submit the form
Ques: 16 Can I develop our own PHP extension?if yes,how?
Ans:
Yes,we can develop a PHP extension like that,
Example:
<?
echo 'PHP';
?>
To save this file as .php extention
Ques: 17 What do you understand by nl2br()?
Ans:
nl2br() function is stands for new line to break tag.
Example:
echo nl2br("R4R Welcomes\nYou");
output:
R4R Welcomes
you
Ques: 18 How function strstr and stristr both work in PHP?
Ans:
Generally, Both function strstr and stristr are same except one thing stristr is a case sensitive where as strstr is an non-case sensitive.We use strstr to match the given word from string.
Syntax:
syntax:
strstr(string,match word)
Examle:
<?php
$email_id = 'abc@xyz.com';
$id_domain = strstr($email_id, '@');
echo $id_domain;
?>
output:
@xyz.com
Ques: 19 In PHP can I get the browser properties?
Ans:
Using get_browser function we can get the browser properties in PHP.
Example:
$browser_properties = get_browser(null, true);
print_r($browser_properties);
Ques: 20 How we can increase the execution time of a PHP script?
Ans:
I have given you some function using them you can increase the execution time of a PHP script.Default time for execution of a PHP script is 30 seconds.
These are,
1.set_time_limit()//change execution time temporarily.
2.ini_set()//change execution time temporarily.
3. By modifying `max_execution_time' value in PHP
configuration(php.ini) file.//change execution time permanent.
Goto Page:
1
2 3 4 5
PHP Objective
PHP Objective Questions And Answers
PHP Interview Questions And Answers
PHP Subjective Questions And Answers
R4R,PHP Objective, PHP Subjective, PHP Interview Questions And Answers,PHP,PHP Interview,PHP Questions ,PHP Answers