Question: 1.
What does PHP stand for?
i) Personal Home Page
ii) Hypertext Preprocessor
iii) Pretext Hypertext Processor
iv) Preprocessor Home Page
Both i) and iii)
Both ii) and iv)
Only ii)
Both i) and ii)
PHP files have a default file extension of..
.html
.xml
.php
.ph
.asp
.jsp
A PHP script should start with ___ and end with ___:
< php >
< ? php ?>
<?php ?>
<% %>
Which of the following is/are a PHP code editor?
i) Notepad
ii) Notepad++
iii) Adobe Dreamweaver
iv) PDT
Only iv)
All of the mentioned.
i), ii) and iii)
Only iii)
Which of the following must be installed on your computer so as to run PHP script?
i) Adobe Dreamweaver
ii) PHP
iii) Apache
iv) IIS
All of the mentioned.
Only ii)
ii) and iii)
ii), iii) and iv)
Which of following variables can be assigned a value to it?
i) $3hello
ii) $_hello
iii) $this
iv) $This
All of the mentioned
Only ii)
ii), iii) and iv)
ii) and iv)
What will be the output of the following code?
<?php
$foo = 'Bob';
$bar = &$foo;
$bar = "My name is $bar";
echo $bar;
echo $foo;
?>
Error
My name is BobBob
My name is BobMy name is Bob
My name is Bob Bob
Which of the following PHP statements will output Hello World on the screen?
i) echo (“Hello World”);
ii) print (“Hello World”);
iii) printf (“Hello World”);
iv) sprintf (“Hello World”);
i) and ii)
i), ii) and iii)
All of the mentioned
i), ii) and iv)
<?php $i = 0;
while ((--$i > ++$i) - 1){ print $i;
} ?>
<?php $color = red;
echo $color . red ;
?>
<?php $color1 = red;
$color2 = red;
echo $color1 + $color2;
?>
<?php define('GOOD_OCTAL', 0700);
define('BAD_OCTAL', 0600);
print GOOD_OCTAL;
print '
';
print BAD_OCTAL;
?>
384
0800
<?php $a1 = array(red, green);
$a2 = array(blue, yellow);
print_r(array_merge($a1, $a2));
?>
Array ( [0] => red [1] => green)
Array ( [0] => blue [1] => yellow [2] => red [3] => green )
Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Array ( [0] => blue [1] => yellow )
start_session()
session_start()
session_begin()
begin_session()
<?php $a1 = array_fill(3, 4, blue);
$b1 = array_fill(0, 1, red);
print_r($a1);
echo
;
print_r($b1);
?>
Array ( [3] => blue [4] => blue)
Array ( [0] => red )
Array ( [4] => blue [5] => blue [6] => blue)
Array ( [0] => red )
Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ()
Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
Array ( [0] => red )
<?php $i = ;
while ($i = 10){ print hi;
}print hello;
?>
<?php $a1 = array(a=>red, b=>green, c=>blue, d=>yellow);
$a2 = array(e=>red, f=>green, g=>blue);
$result = array_diff($a1, $a2);
print_r($result);
?>
Array ( [d] => yellow )
Array ( [c] => blue )
Array ( [a] => red )
Array ( [e] => yellow )
<?php define(VAR_NAME,test);
${VAR_NAME} = value;
echo VAR_NAME;
echo ${VAR_NAME};
?>
<?php $i = 5;
while (--$i > 0 && ++$i){ print $i;
} ?>
<?php $color = red;
$color = green;
echo $color;
?>
<?php $color1 = red;
$color2 = green;
echo $color1 . $color2;
?>
<?php $a = array(a=>red, b=>green, c=>blue);
echo array_shift($a);
print_r ($a);
?>
green
red
redArray( [c] => green [c] => blue )
redArray( [b] => green [c] => blue )
<?php define('IF', 42);
echo IF: , IF;
?>
<?php $a = array(A, Cat, Dog, A, Dog);
print_r(array_count_values($a));
?>
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
Array ( [A] => 2 [Cat] => 2 [Dog] => 1 )
Array ( [A] => 1 [Cat] => 1 [Dog] => 2 )
Array ( [A] => 2 [Cat] => 1 [Dog] => 1)
time()
mktime()
mrtime()
mtime()
<?php $a = array(red, green, blue);
array_pop($a);
print_r($a);
?>
Array ( [0] => red [1] => green )
Array ( [0] => green [1] => blue )
Array ( [0] => red [1] => blue )
Array ( [0] => blue [1] => blue )
<?php /*echo Hello world;
*/ ?>
/* Hello world */
<?php printf( date(t) ) ?>
<?php $fname = array(Peter, Ben, Joe);
$age = array(35, 37, 43);
$c = array_combine($fname, $age);
print_r($c);
?>
Array ( Peter Ben Joe )
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
Array ( 35 37 43 )
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
totime(+45)
totime(+45 days)
strtotime(+45 days)
strtotime(-45 days)
<?php echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
?>
<?php define(__LINE__, PHP is a scripting language);
echo __LINE__;
?>
<?php class Constants{ define('MIN_VALUE', '0.0');
define('MAX_VALUE', '1.0');
public static function getMinValue() { return self::MIN_VALUE;
} public static function getMaxValue() { return self::MAX_VALUE;
}}echo Constants::getMinValue();
echo Constants::getMaxValue();
?>
<?php $color1 = red;
$color2 = green;
echo $color1 + $color2;
?>
<?php $age = array(Peter=>35, Ben=>37, Joe=>43);
print_r(array_change_key_case($age, CASE_UPPER));
?>
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
Array ( [peter] => 35 [ben] => 37 [joe] => 43 )
Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
Array ( [PeTeR] => 35 [BeN] => 37 [Joe] => 43 )
<?php $i = 0;
while ($i = 10){ print hi;
}print hello;
?>
<?php define(GREETING, PHP is a scripting language);
echo $GREETING;
?>
<?php $color1 = red;
$color2 = green;
echo $color1.$color2;
?>
<?php $i = 2;
while (++$i){ while (--$i > 0) print $i;
} ?>
lastmod()
getlastmod()
last_mod()
get_last_mod()
<?php $color1 = red;
$color2 = 1;
echo $color1 + $color2;
?>
<?php $i = 5;
while (--$i > 0 || ++$i){ print $i;
} ?>
<?php define('GREETING_TEST', 'PHP is a scripting language', true);
echo GREETING_TESt;
$changing_variable = 'test';
echo constant('GREETING_' . strtoupper($changing_variable));
?>
PHP is a scripting language
GREETING_TEST
<?php define(NEW_GOOD_NAME_CONSTANT, I have a value);
define(OLD_BAD_NAME_CONSTANT, NEW_GOOD_NAME_CONSTANT);
�echo NEW_GOOD_NAME_CONSTANT;
echo OLD_BAD_NAME_CONSTANT;
?>
<?php $i = 0;
while (++$i && --$i){ print $i;
} ?>
<?php $cars = array(Volvo, BMW, Toyota);
echo I like . $cars[0] . , . $cars[1] . and . $cars[2] . .;
?>
<?php define(GREETING, PHP is a scripting language, true);
echo GREETING;
echo
echo GREETING;
?>
GREEtING
PHP is a scripting language
$date = Date(22 JUNE 2013)
$date = new Date(JUNE 22 2013)
$date = DateTime(22 JUNE 2013)
$date = new DateTime(22 JUNE 2013)
session.domain
session.path
session.cookie_path
session.cookie_domain
<?php $i = 0;
while(++$i || --$i){ print $i;
} ?>
<?php class myObject { }define('myObject::CONSTANT', 'test');
echo myObject::CONSTANT;
?>
save_data
session.save
session.save_data
session.save_handler
<?php $i = 5;
while (--$i > 0){ $i++;
print $i;
print hello;
} ?>
<?php $color1 = 1;
$color2 = 1;
echo $color1 + $color2;
?>
<?php echo Today is .date(F d, Y) ?>
<?php $cars = array(Volvo, BMW, Toyota, Honda, Mercedes, Opel);
print_r(array_chunk($cars, 2));
?>
Array ( [0] => Array ( [1] => Volvo [2] => BMW ) [1] => Array ( [1] => Toyota [2] => Honda ) [2] => Array ( [1] => Mercedes [2] => Opel ) )
Array ( [1] => Array ( [1] => Volvo [2] => BMW ) [2] => Array ( [1] => Toyota [2] => Honda ) [3] => Array ( [1] => Mercedes [2] => Opel ) )
Array ( [0] => Array ( [0] => Volvo [1] => Volvo ) [1] => Array ( [0] => BMW [1] => BMW ) [2] => Array ( [0] => Toyota [1] => Toyota ) )
Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )
<?php $i = 2;
while (++$i){ while ($i --> 0) print $i;
} ?>
<?php $color1 = red;
$color2 = 1;
$color3 = greyecho $color1 + $color2 . $color3;
?>
Answer Sheet
1 | D | PHP previously stood for Personal Home Page now stands for Hypertext Preprocessor. |
2 | C | |
3 | C | Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them. |
4 | B | Any of the above editors can be used to type php code and run it. |
5 | D | To run PHP code you need to have PHP and a web server, both IIS and Apache are web servers.You can choose either one according to your platform. |
6 | D | A variable can’t start with a number. Also $this is a special variable that can’t be assigned, but $This can be assigned |
7 | C | The $bar = &$foo; line will reference $foo via $bar. |
8 | B | echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser. |
9 | A | ($i > ++$i) evaluates to 0 but -1 makes it enters the loop and prints i which is 0. |
10 | C | Use of undefined constant red. |
11 | C | + does not return 1 if the variables are equal. |
12 | A | Anything starting from 0 is evaluated as an octal. |
13 | C | The array_merge() function merges one or more arrays into one array. |
14 | B | |
15 | D | The array_fill() function fills an array with values. |
16 | B | While condition always gives 1. |
17 | A | The array_diff() function compares the values of two (or more) arrays, and returns the differences. |
18 | C | ${VAR_NAME}creates a new variable which is not same as VAR_NAME. |
19 | A | You can change this name by using the session.name directive. |
20 | C | |
21 | B | As it is && operator it is being incremented and decremented continuously. |
22 | B | The variable contains the last value which has been assigned. |
23 | D | The . operator is used to join to strings. |
24 | D | The array_shift() function removes the first element from an array, and returns the value of the removed element. |
25 | B | Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or through user defined functions(user). |
26 | D | Keyword like IF cannot be used as constant names. |
27 | C | When the format is E the timezone is identified and returned…example America/New_York. |
28 | A | The array_count_values() function counts all the values of an array. |
29 | B | |
30 | A | The array_pop() function deletes the last element of an array. |
31 | B | /* */ is used for commenting multiple lines. |
32 | A | The t parameter is used to determine the number of days in the current month. |
33 | B | The array_combine() function creates an array by using the elements from one keys array and one values array. |
34 | C | Thestrtotime()function and GNU date syntax is used to calculating the date x days from the present date. |
35 | D | April has 30 days and the above date is 31 therefore Invalid is returned. |
36 | C | __LINE__ is a magical constant that gives the current line number and cannot be used a variable/constant name. |
37 | D | In a class constants should be defined const MIN_VALUE = 0.0; const MAX_VALUE = 1.0; instead. |
38 | C | + operator does not join both the strings. |
39 | C | The array_change_key_case() function changes all keys in an array to lowercase or uppercase. |
40 | B | While condition always gives 1. |
41 | B | Constants do not need a $ before them, they are referenced by their variable names itself. |
42 | D | It has to be $color1 = red; and $color2 = green; therefore the error. |
43 | D | The loop never ends as i is always incremented and then decremented. |
44 | B | The getlastmod() function returns the value of the pages Last Modified header or FALSE in the case of an error. |
45 | D | + just returns the numeric value even though it is inside double quotes. |
46 | A | As it is || operator the second expression is not evaluated till i becomes 1 then it goes into a loop. |
47 | B | The directive which determines this is session.cache_expire. |
48 | A | echo constant(x) output x, and x here is the concatenation of GREETING_ and $changing variable with. operator. |
49 | A | The lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should be set to 3600. |
50 | B | Constants can be set as values for other constants. |
51 | C | The first condition itself fails thus the loop exits. |
52 | B | The array() function is used to create an array. Each elements are assigned ab index as the rule of an array. So, calling $cars[0] will print element at index 0 and so on. |
53 | D | Since the third parameter is true in define(GREETING, PHP is a scripting language, true) is true GREETING becomes case insensitive. |
54 | D | ThedateTime()method is class constructor. You can set the date either at the time of instantiation or later by using a variety of mutators. |
55 | A | Day of month, with leading zero is represented by D; Daylight saving time by I; Day of month, without zeros by j. |
56 | D | The directivesession.cookie_domaindetermines the domain for which the cookie is valid. |
57 | A | As it is || operator the second expression is not evaluated and i is always incremented, in the first case to 1. |
58 | B | Class constants cannot be defined outside class. |
59 | C | Thesession.gc_maxlifetimedirective determines this duration. It can be set to any required value. |
60 | C | |
61 | D | Its prototype follows: session.save_handler = files|mm|sqlite|user. |
62 | A | i is decremented in the first while execution and then continuously incremented back. |
63 | B | + can be used to add to integer values which are enclosed by double-quotes. |
64 | D | F is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year. |
65 | D | The array_chunk() function splits an array into chunks of new arrays. |
66 | A | The loop ends when i becomes 0. |
67 | B | The prototype of this function is: string date(string format [, int timestamp]). |
68 | A | + gives the value 1 and . is used to give join 1 and grey. |
0 comments:
Post a Comment