WorksheetsPHP Quiz - 1
Total questions: 75
Worksheet time: 1hrs 17mins
What type of language is PHP
Client Side
Server Side
Browser Side
Web Side
PHP is executed on
The Server
The Browser
The Website
The Machine
We create re-usable code blocks by placing them inside?
Variables
Parameters
Code Blocks
Functions
Sometimes we only want certain code to execute if a condition is true. How do we test for that?
Loop
If Statement
Integer
Variable
What is a integer?
It's a Whole Number
It's a Decimal Number
It's a True or False Declaration
It's a String of Text
What is a String?
Text
Number
True
Loop
What is a Boolean
It's Just Text
It's a Number
It's Just True
It's True or False
What if we want a block of code to execute several times?
Use a Variable
Use a Function
Use a Loop
Use a Leap
$colours = array("black, blue, Red, Green") - How do I access "Red" ?
$colours[0];
$colours[2];
$colours[1]
$colours[3];
How do I print out the values of the variable "name" ?
$name;
include $name;
echo $name;
echo $name
function sayMyName(name) {} ; - How do I call tat function
sayMyname();
$sayMyName;
$sayMyName();
sayMyName("John")';
What does i++ do ?
Adds the text on to the end of i
Adds i on to the end of something
Adds i on to the existing value of i
Adds 1 to the current value of iThis is a correct answer
What type of variable is this: $isMale = false;
Integer
Boolean
String
char
In an IF statement we can have 2 conditions tested. Which keyword allows this?
Else
if Else
Else if
OR
$a = 4 ; $b = 6; $c = $a + $b; What is the value of variable "c" ?
6
8
10
None
$a = "Ram"; $n = "Kumar"; $fullName = $f + $n; What is the value of $fulName
RamKumar
Ram Kumar
Ram
None
$a = "Ram"; $n = "Kumar"; $fullName = $f . $n; What is the value of $fulName
RamKumar
Ram Kumar
Kumar
None
function declarations can have (a) assigned to them?
Function calls can have____________ inside them.
Parameters
Arguments
Variables
Types
What
does PHP stand for?
Private
Home Page
Hypertext
Preprocessor
Pretext
Hypertext Processor
Preprocessor
Home Page
Which
of the following function of String object is used to match a regular
expression against a string?
concat()
match()
search()
replace()
Which
one of the following databases has PHP supported almost since the beginning?
Oracle
Database
SQL
SQL+
MySQL
Who is
the father of PHP?
Rasmus
Lerdorf
Willam
Makepiece
Drek
Kolkevi
List
Barely
PHP
files have a default file extension of_______
.html
.xml
.php
.ph
A
function in PHP which starts with __ (double underscore) is known as
__________
Magic
Function
Inbuilt
Function
Default
Function
User
Defined Function
Which
of the below statements is equivalent to $add += $add?
$add =
$add
$add =
$add +$add
$add =
$add + 1
$add =
$add + $add + 1
Client
Side Script executed by ____________
Webserver
IIS
Apache
Browser
A
function name cannot start with a ____
alphabet
underscore
number
Both C
and B
Which
built-in method removes the last element from an array and returns that
element?
last()
get()
pop()
None of
the above.
Why
should we use functions?
Reusability
Easier
error detection
Easily
maintained
All of
the above
Which
of the following function of Array object extracts a section of an array and
returns a new array?
reverse()
shift()
slice()
some()
Comments in PHP are written with ...
$
//
<!-- ... -->
" ... "
The correct way of defining a variable in PHP?
$variable name = value;
$variable_name = value
$variable name as value;
$variable_name = value;
The correct way to print out the values of the variable "name" is ...
$name;
include $name;
echo $name;
echo $name
<?php
$sum= 15+30;
echo "$sum";
?>
The Correct output is ...
Error
15+30
45
No Answer
<?php
$x = 10;
$y = 6;
echo $x % $y;
?>
The correct type of operator in the code above is ...
Arithmetic Operators
Assignment Operators
Comparison Operators
Increment / Decrement Operators
<?php
$number = 20;
if($number < 10){
echo "SMA ABBS";
}else{
$sum = $number + 10;
echo "$sum";
}
?>
The output is ...
SMA ABBS
20
30
Error
<?php
for ($x=1; $x<=10; $x++){
echo "$x ";
}
?>
the output is ...
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
5 6 7 8 9 10
No answer
What is the correct output of the given code <?php
$NUM1 = 3;
$NUM2 = 4;
$NUM3 = $NUM1 ** $NUM2;
echo $NUM3;
?>
12
81
Garbage Value
None of the above
The "**" operator belongs to which category of operators?
Arithmetic operator
Logical operator
Comparison operator
Conditional operator
Which of the following are comparison operators in PHP?
A. ==
B. !=
C. ===
D. <
A and B
C and D
A,B and C
A,B,C and D
What is the Output?
<?php
#echo "Hello World"
echo "#Hello World";
?>
Hello World #Hello World
Hello World
#Hello World
Error
What is the Output
<?php
$color=red;
echo "$color";
?>
red
$color
No answer
Error
All variables in PHP start with which symbol?
?
$
!
=
How do you create an array in PHP?
$cars = "Volvo", "BMW", "Toyota";
$cars = array["Volvo", "BMW", "Toyota"];
$cars = array("Volvo", "BMW", "Toyota");
What is the Output:
<?php
$color= "red";
echo "$color";
echo "$COLOR";
echo "$Color";
?>
redredred
redred
red
Error
What is the Ouput
<?php
$color1="green";
$color2="yellow";
echo "$color1" + "$color2";
?>
greenyellow
green yellow
Error
0
What is the output?
<?php
define(GREETING, " PHP is a Scripting Language");
echo "$GREETING;
?>
$GREETING
no output
GREETING
PHP is a Scripting Language
<?php
$x=10;
$y=4;
$z=3;
echo ($x % ($y) + $z);
?>
5
3
0
1
What is the Output?
<?php
$four4 =4;
$three3 = 3;
$two2 = 2;
echo " $four4 + $three3 / $two2 - 1"
4.5
7
3.5
Error
PHP server scripts are surrounded by delimiters, which?
<?php...?>
<?php>...</?>
What is the correct way to create a function in PHP?
new_function myFunction()
create myFunction()
function myFunction()
PHP allows you to send emails directly from a script
False
True
What is the correct way to add 1 to the $count variable?
count++;
$count =+1
++count
$count++;
Which operator is used to check if two values are equal and of same data type?
===
==
!=
=
By using the PHP, create the following variables
$x=10; $y=7;
Then write code to print out the following:
10 + 7 = 17
10 - 7 = 3
10 * 7 = 70
10 / 7 = 1.4285714285714
10 % 7 = 3
Use numbers only in the above variable assignments, not in the echo statements.
(a)
Write the output of the code given.
(a)
Write the output of the code given.
(a)
What is the correct way to end a PHP statement?
;
</php>
.
New line
In PHP you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings:
FALSE
TRUE
Which superglobal variable holds information about headers, paths, and script locations?
$GLOBALS
$_GET
$_SERVER
$_SESSION
1.
PHP is a _________.
Open Source Language
Widely Used Language
Server side scripting language
All of the above
4.
PHP is case sensitive in what way?
It's never case sensitive, don't worry about it.
Only when referring to variables
When referring to classes, functions or variables
All the time!
7.
What does CRUD operation stands for in PHP?
Create
Read
Upload
Delete
Create
Read
Update
Delete
Concatenate
Read
Update
Destroy
Concatenate
Read
Upload
Delete
Which of the following is the correct code snippet for a foreach statement in PHP?
foreach ($variable as $key => $value)
foreach ($variable => $key as $value)
foreach ($ctr = 0; $ctr < $array_size; $ctr++)
foreach ($variable => $key => $value)
What are the two types of array in php
Indexed, sequence
Associative, sequence
Indexed, associative
None
$a=array("Timmy","Jimmy");
Is an example of
Indexed array
Associative array
Sequence array
None
$a=array("Jimmy"=>10,"mummy"=>20);
Is an example of
Sequence array
Indexed array
Associative array
None
function add(&a)
{
$a=10;
echo $a;}
$a=33;
This is an example for
Call by value
Call by reference
Both of the above
None
<?php
function add()
{
global $a=10;
echo $a;
}
add();
$a+=10;
?>
Output is
10
15
20
30
$a="deepan";
$b="Deepan";
if(strcmp($a,$b))
{
echo "equal";
}
else{
echo " not equal";}
Output is
Equal
Not equal
Error
None
i) /?
ii) //
iii) #
iv) /* */
i) int $num = 111;
ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;
<?php
$num = 1;
$num1 = 2;
print $num . "+". $num1;
?><?php
$num = "1";
$num1 = "2";
print $num+$num1;
?>