Ques: 1 Explain the difference between $message and $$message?
$message is used to store variable data. $$message can be used to
store variable of a variable. Data stored in $message is fixed while
data stored in $$message can be changed dynamically.
E.g. $var1 = ‘Variable 1’
This can be interpreted as $ Variable 1=‘variable2’;
For me to print value of both variables, I will write
Ques: 2 What is session hijacking?
Session hijacking is the misuse of a valid computer session. It is
used to attain unauthorized and illegal access to a system. This
access is attained using the “brute force” attack where in he tries
multiple id’s to login in a system while the session is in progress.
The most common method of session hijacking is IP spoofing where an
attacker uses source-routed IP packets to insert commands into an
active communication between two systems on a network and pretending
itself as one of the authenticated users.
Ques: 3 How
session will work when we disable cookies of client browser?
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?
When we use array_search() function if it found the particular value
than it will return index corresponding to array value.
$Emp_name_array = array(0 => 'vivek', 1 => 'umang', 2 => 'shrish', 3
=> 'jalees');
$key = array_search('umang', $Emp_name_array);
$key = array_search('vivek', $Emp_name_array); // return
$key = 0;
Ques: 5 How
you differentiate among sort(),assort() and Ksort()?
This function sorts an array. Elements will be arranged
from lowest to highest when this function has completed.
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
----------------------------OUTPUT---------------------
-------------------------------------------------------
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
$fruits = array("d" => "lemon", "a" => "orange", "b" =>
"banana", "c" => "apple");
foreach ($fruits as $key => $val) {
--------------------OUTPUT------------------------
--------------------------------------------------
Sorts an array by key, maintaining key to data
correlations. This is useful mainly for associative arrays.
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana",
foreach ($fruits as $key => $val) {
--------------------OUTPUT----------------------------
------------------------------------------------------
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.
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
The
above example will output:
Assort-Sort an array and maintain index association
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana",
"c" => "apple");
foreach ($fruits as $key => $val) {
The
above example will output:
ksort — Sort an array by key
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana",
"c"=>"apple");
foreach ($fruits as $key => $val) {
The
above example will output:
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
The
above example will output:
Assort-Sort an array and maintain index association
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana",
"c" => "apple");
foreach ($fruits as $key => $val) {
The
above example will output:
ksort — Sort an array by key
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana",
"c"=>"apple");
foreach ($fruits as $key => $val) {
The
above example will output:
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
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
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.
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.
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
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
The
above example will output:
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
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
The
above example will output:
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,” returningnothing, 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);
The
outcome looks like this:
Array ( [0] => 12 [1] => 42 [2] => 43 [3] => 57 [4] => 78 [5] => 98
It’s important to note that key/value associations are not
maintained. Consider the
$states = array("OH" => "Ohio", "CA" => "California", "MD" =>
"Maryland");
Array ( [0] => California [1] => Maryland [2] => Ohio )
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 *?.
I have given you a example which definitely solved your query.
\ for slah and * for adding values
Ques: 7 Why
is PHP-MySQL used for web Development?
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 ?
I have given you a function using them we can change a timezone into
another timezone.
date_default_timezone_set() function
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?
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?
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?
I have given you a example using this you can create a database.
$con =mysql_connect("localhost","vivek","vivabh");
die('Could not connect: ' . mysql_error());
if
(mysql_query("CREATE DATABASE my_db",$con))
echo "Database has been created";
echo "Error to create database: " . mysql_error();
Ques: 12
What do you understand about Joomala in PHP?
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?
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
Ques: 14
What do you understand about Implode and Explode functions?
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(,).
$array = array('First_Name', 'Email_Id', 'Phone_NO');
$comma_separated_string = implode(",", $array);
echo $comma_separated_string;
First_Name,Email_Id,Phone_No
We
use Explode function to convert the string value those are separated
with coma(,) into array.
$comma_separated_string = string('First_Name,Email_Id,Phone_No');
$array = Explode(",", $coma_separated_string);
Ques: 15 Can
we submit a form without submit button?
Using JavaScript we can submit a form without submit button.
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?
Yes,we can develop a PHP extension like that,
To
save this file as .php extention
Ques: 17
What do you understand by nl2br()?
nl2br() function is stands for new line to break tag.
echo nl2br("R4R Welcomes\nYou");
Ques: 18 How
function strstr and stristr both work in PHP?
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.
strstr(string,match word)
$email_id = 'abc@xyz.com';
$id_domain = strstr($email_id, '@');
Ques: 19 In
PHP can I get the browser properties?
Using get_browser function we can get the browser properties in PHP.
$browser_properties = get_browser(null, true);
print_r($browser_properties);
Ques: 20 How
we can increase the execution time of a PHP script?
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.
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.
Ques: 21 How we can get the value of current session id?
We can get the value of our current session id by using
session_id().It returns the value of our current session id.
Ques: 22 How we use ereg_replace() and eregi_replace()in PHP?
The main difference b/w ereg_replace and eregi_replace() is
that,eregi_replace is case sensitive. Example:In eregi_replace() it
think both \'welcome\' and \'WeLCome\' are different. where as
ereg_replace() is not case sensitive.
Example:In ereg_replace() it think both \'welcome\' and \'WeLCome\' are same.
Ques: 23 Which type of inheritance exists in PHP?
PHP supports Multi-level inheritance.It doesn't support multiple
inheritence.But using interface we can achieve multiple
inheritance in PHP.
Ques: 24 What do you understand about pear in PHP?
Basically PEAR is stands for PHP Extension And Repository.PEAR is a
framework and distribution system using that we can make PHP
component reusable.It has huge collection of different classes.We
use this for advance scripting.Example: Database,Mail,HTTP etc.
Ques: 25 Tell me how to use COM components in PHP?
We use COM component in PHP by using that manner,
Example:
<?php
$objCom = new COM(�AddNumber.math�);
$output = $objCom ->AddTwoNum(4,5);
echo $output;
?>
Ques: 26 Tell me default session time in PHP and how can I change it?
The default session time in PHP is 14400.We can change it like that
manner,
Synatx:
$session_time_Limit="14400";
ini_set(session.gc_maxlifetime,$session_time_Limit);
Ques: 27 How we use copy() and move() file uploading functions in PHP?
When we use copy function it copy the file from source location to
destination location and keep original file to the source location.
Syntax:
copy($_FILES['uploadedfile']['tmp_name'], $destination_path)
Where as when we use move function it copy the file from source location to destination location and delete original file from source location.
Syntax:
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $destination_path)
Ques: 28 How can we find out the name of the current executing file?
I have given you a example that gives you the name of current
executing file,
Example:
<?php
$File_Name = $_SERVER["SCRIPT_NAME"];
echo $File_Name;
?>
Ques: 29 What is the main difference b/w include_once() and require_once() in PHP?
The main difference b/w include_once() and require_once() is that,
In PHP if file is not exist and specified with include_once() it
gives show warning message.Where as if we specified file as
require_once() it giver a fatal error.
Ques: 30 what are the constant value in PHP?can we write them without $ symbol?
We can't change the value of constant.Yes,we can write constant
value in PHP.Below I have given you a example:
define("CONSTANT","R4R Welcomes You");
echo "CONSTANT";
output:
R4R Welcomes You
|