Website Dev't and PHP Question
Website Dev't and PHP Question
DEPARTMENT OF WD$DBA
WORK SHEET
PREPARED BY GEMECHU A
1. What is PHP?
Explanation: PHP is an open-source server-side scripting language that is used to build dynamic
and interactive web pages or web applications.
a) Drek Kolkevi
b) Rasmus Lerdorf
c) Willam Makepiece
d) List Barely
P R E P A R E D B Y GEMECHU . A Page 1
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
Explanation: PHP previously stood for Personal Home Page now stands for “Hypertext
Preprocessor”.
a) <?php ?>
d) <? ?>
Explanation: 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.
5. Which of the following is the correct way to add a comment in PHP code?
a) #
b) //
c) /* */
Explanation: In PHP, /* */ can also be used to comment just a single line although it is used for
paragraphs. // and # are used only for single-line comments.
P R E P A R E D B Y GEMECHU . A Page 2
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a) .php
b) .ph
c) .xml
d) .html
Explanation: PHP allows us to create our own user-defined functions. Any name ending with an
open and closed parenthesis is a function. The keyword function is always used to begin a
function.
<?php
$x = 10;
$y = 20;
else
?>
P R E P A R E D B Y GEMECHU . A Page 3
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a) no output
b) Welcome to Sanfoundry
d) error
Output:
a) $3hello
b) $_hello
c) $this
d) $5_Hello
Explanation: A variable in PHP can not start with a number, also $this is mainly used to refer
properties of a class so we can‟t use $this as a user defined variable name.
<?php
?>
a) 6
b) 5
P R E P A R E D B Y GEMECHU . A Page 4
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
c) 4
d) 3
Explanation: function count() will return the number of elements in an array. The parameter 1
counts the array recursively i.e it will count all the elements of multidimensional arrays.
<?php
function multi($num)
if ($num == 3)
if ($num == 7)
if ($num == 8)
if ($num == 19)
multi($can);
?>
a) Correct Answer
P R E P A R E D B Y GEMECHU . A Page 5
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
b) Is The
c) I Wonder
d) Which One
Explanation: The stripos() function finds the position of the first occurrence of a string inside
another string. In this case it returns 7.
12. Which of the following PHP functions can be used for generating unique ids?
a) md5()
b) uniqueid()
c) mdid()
d) id()
Explanation: The function uniqueid() is used to generate a unique ID based on the microtime
(current time in microseconds). The ID generated from the function uniqueid() is not optimal, as
it is based on the system time. To generate an ID which is extremely difficult to predict we can
use the md5() function.
<?php
class Example
public $name;
function Sample()
P R E P A R E D B Y GEMECHU . A Page 6
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
?>
a) function sample()
c) public $name;
d) class Example
Explanation: Above code is an example of „classes‟. Classes are the blueprints of objects.
Classes are the programmer-defined data type, which includes the local methods and the local
variables. Class is a collection of objects which has properties and behaviour.
<?php
echo $GREETING;
?>
a) $GREETING
b) no output
d) GREETING
Explanation: Constants do not need a $ before them, they are referenced by their variable names
itself.
P R E P A R E D B Y GEMECHU . A Page 7
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a) Default Function
c) Inbuilt Function
d) Magic Function
Explanation: PHP functions that start with a double underscore – a “ ” – are called magic
functions. They are functions that are always defined inside classes, and are not stand-alone
functions.
16. How many functions does PHP offer for searching and modifying strings using Perl-
compatible regular expressions.
a) 10
b) 7
c) 8
d) 9
17. Which of the following web servers are required to run the PHP script?
b) IIS
c) XAMPP
Explanation: To run PHP code you need to have PHP and a web server, both IIS, XAMPP and
Apache are web servers. You can choose either one according to your platform.
18. What will be the output of the following PHP code snippet?
P R E P A R E D B Y GEMECHU . A Page 8
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
<?php
$url = "[email protected]";
?>
c) phpmcq@
d) sanfoundry.com
Explanation: The strstr() function returns the remainder of a string beginning with the first
occurrence of a predefined string.
19. Which of the following PHP functions can be used to get the current memory usage?
a) memory_get_usage()
b) memory_get_peak_usage()
c) get_peak_usage()
d) get_usage()
Explanation: memory_get_usage() returns the amount of memory, in bytes, that‟s currently being
allocated to the PHP script. We can set the parameter „real_usage‟ to TRUE to get total memory
allocated from system, including unused pages. If it is not set or FALSE then only the used
memory is reported. To get the highest amount of memory used at any point, we can use the
memory_get_peak_usage() function.
20. Which one of the following PHP function is used to determine a file‟s last access time?
a) filetime()
b) fileatime()
P R E P A R E D B Y GEMECHU . A Page 9
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
c) fileltime()
d) filectime()
Explanation: The fileatime() function returns a file‟s last access time in Unix timestamp format
or FALSE on error.
<?php
$x = 5;
$y = 10;
function fun()
$y = $GLOBALS['x'] + $GLOBALS['y'];
fun();
echo $y;
?>
a) 5
b) 10
c) 15
d) Error
Explanation: The value of global variable y does not change therefore it‟ll print 10;
P R E P A R E D B Y GEMECHU . A Page 10
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a) function construct()
b) function _construct()
c) classname()
d) _construct()
23. The developers of PHP deprecated the safe mode feature as of which PHP version?
a) PHP 5.3.1
b) PHP 5.3.0
c) PHP 5.1.0
d) PHP 5.2.0
Explanation: This happened because safe mode often creates many problems as it resolves,
largely due to the need for enterprise applications to use many of the features safe mode disables.
24. What will be the value of the variable $input in the following PHP program?
<?php
$input = strip_tags($input,"<i></i>");
echo $input;
?>
P R E P A R E D B Y GEMECHU . A Page 11
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially
wreak havoc on a page.
25. Which of the following variables does PHP use to authenticate a user?
i) $_SERVER['PHP_AUTH_USER'].
ii) $_SERVER['PHP_AUTH_USERS'].
iii) $_SERVER['PHP_AUTH_PU'].
iv) $_SERVER['PHP_AUTH_PW'].
b) i) and iv)
d) i) and ii)
P R E P A R E D B Y GEMECHU . A Page 12
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
Explanation: PDO stands for PHP Data Object. The PDO class provides a common interface to
different database applications.
<?php
$a = 100;
printf("PHP Quiz");
printf("PHP MCQ");
printf("PHP Program");
?>
a)
PHP Quiz
PHP MCQ
PHP Program
b) PHP Quiz
c) No output
d) PHP MCQ
P R E P A R E D B Y GEMECHU . A Page 13
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
i) for loop
a) Only iv)
b) i) and ii)
Explanation: All are supported looping statements in PHP as they can repeat the same block of
code a given number of times, or until a certain condition is met.
a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;
Explanation: A backslash is used so that the dollar sign is treated as a normal string character
rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as
the escape character.
a) PHP 6
b) PHP 4
c) PHP 5
P R E P A R E D B Y GEMECHU . A Page 14
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
d) PHP 5.3
<?php
$x = 4;
$y = 3
$z = 1;
$z = $z + $x + $y;
echo "$z";
?>
a) 15
b) 8
c) 1
d) $z
Explanation: Normal addition of variables x, y and z occurs and result of 8 will be displayed.
<?php
$a = "$winner";
$b = "/$looser";
echo $a,$b;
?>
P R E P A R E D B Y GEMECHU . A Page 15
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a) /
b) $looser
c) /$looser
d) $winner/$looser
Explanation: Since variables $winner and $looser is not defined we only see / as output.
33. Which one of the following is the default PHP session name?
a) PHPSESSIONID
b) PHPIDSESS
c) PHPSESSID
d) PHPSESID
Explanation: PHPSESSID is the default PHP session name. You can change this name by using
the session.name directive.
<?php
$mcq = 1;
switch(print $mcq)
case 2:
print "HTML";
break;
case 1:
P R E P A R E D B Y GEMECHU . A Page 16
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
print "CSS";
break;
default:
print "JavaScript";
?>
a) error
b) 1HTML
c) 1JavaScript
d) 1CSS
<?php
define("VAR_NAME","test");
${VAR_NAME} = "value";
echo VAR_NAME;
echo ${VAR_NAME};
?>
a) testtest
b) testvalue
P R E P A R E D B Y GEMECHU . A Page 17
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
d) test
36. Which PHP function displays the web page‟s most recent modification date?
a) getlastmod()
b) get_last_mod()
c) lastmod()
d) last_mod()
Explanation: The function getlastmod() gets the time of the last modification of the main script
of execution. It returns the value of the page‟s last modified header or FALSE in the case of an
error.
<?php
$i = 5;
print $i;
?>
a) 555555555…infinitely
b) 54321
c) error
d) 5
P R E P A R E D B Y GEMECHU . A Page 18
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
<?php
function constant()
echo greeting;
?>
a) GREETING
b) Welcome to Sanfoundry
c) ERROR
d) greeting
Explanation: By default, constants are case sensitive in php. But the third parameter in define(),
if set to true, makes constants case insensitive.
39. Which variable is used to collect form data sent with both the GET and POST methods?
a) $_BOTH
b) $REQUEST
c) $_REQUEST
d) $BOTH
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an
HTML form.
P R E P A R E D B Y GEMECHU . A Page 19
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
<?php
echo pos($php);
?>
a) Function
b) File
c) Strings
d) Array
Explanation: The pos() function returns the value of the current element in an array, and since no
operation has been done, the current element is the first element.
a) 1
b) 5
c) 12
d) Error
Explanation: ?: is known as ternary operator. If condition is true then the part just after the ? is
executed else the part after : .
a. Data types
b. Keywords
P R E P A R E D B Y GEMECHU . A Page 20
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
c. Prototypes
d. Declaration statements
43. Which of these is the correct way in which we can call the JavaScript code?
a. Triggering Event
b. Preprocessor
c. Function/Method
d. RMI
44. Which of these functions of the Number Object would format a number with different
numbers of digits to the decimal‟s right?
a. toFixed()
b. toExponential()
c. toLocaleString()
d. toPrecision()
45. Out of the following functions of the string object, which one would return the character in
any string via the specified number of characters starting at a specified position?
a. search()
b. substr()
c. split()
d. slice()
46. Look at the snippets given below and check the one in which the variable “a” isn‟t equal to
the “NULL”.
a. if (a!)
P R E P A R E D B Y GEMECHU . A Page 21
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
b. if(a!=null)
c. if(a!==null)
d. if(a!null)
47. In JavaScript, what do we use for calling the expression for function definition?
a. Function literal
b. Function prototype
c. Function declaration
d. Function calling
a. Functional Expression
c. Primary Expression
d. Invocation Expression
8. Which of these operators are used for checking if a specific property exists?
a. in
b. within
c. exist
d. exists
49. “The expression that can appear legally on an assignment expression‟s left side” is a common
explanation for variables, elements of arrays, and properties of objects. These are known as
:
a. Prototypes
P R E P A R E D B Y GEMECHU . A Page 22
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
b. Properties
c. Lvalue
d. Definition
50. Which of these is a correct output for the JavaScript code given below?
string X= “Hey”;
string Y=”There”;
alert(X+Y);
a. Hey There
b. Hey_There
c. HeyThere
d. undefined
51. Which of these is known as the Equality operator used for checking whether both the values
are equal?
a. =
b. ==
c. ===
d. &&
52. In case a value of an operator is NULL, then the unary operator would return the
typeof.
a. object
b. boolean
c. string
P R E P A R E D B Y GEMECHU . A Page 23
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
d. undefined
a. debugger
b. use strict
c. with
d. if
a. //
b. \\
c. \* */
d. \* *\
55. In the line of code given below, what will the “datatype” written in brackets be called?
article[datatype]=assignment_value;
a. An object
b. A String
c. Floating point
d. An integer
56. In the line of code given below, the prototype represents the .
functionx(){};
a. Prototype of a function
b. Function x
P R E P A R E D B Y GEMECHU . A Page 24
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
c. Not valid
d. A custom constructor
57. Which of these methods or operators are used for identifying an array?
a. isarrayType()
b. ===
c. ==
d. Typeof
58. A function‟s execution would stop whenever a program control would encounter the
statement in the function‟s body.
a. goto statement
b. break statement
c. continue statement
d. return statement
a.x(g,h);
a. a [ “x” ] ( g , h );
c. x( g&&h );
d. a (x )[ “g” , “h” ];
a. function
P R E P A R E D B Y GEMECHU . A Page 25
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
b. main
c. init
d. Void
61. How to check the number of elements inside the HTML form?
a. document.form.elements.count
b. document.form.count
c. document.form.length
d. document.form.elements.length
62. Which javascript method returns the string starting at the specified position?
a. substr()
b. getSubstring()
c. slice()
d. None of the above
a. window.reload()
b. location.reload()
c. window.refresh()
d. location.refresh()
a. showalert("Hello World");
b. msg("Hello World");
c. alert("Hello World");
d. msgBox("Hello world");
P R E P A R E D B Y GEMECHU.A Page 26
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a. /*This is a comment*/
b. $$This is a comment$$
c. **This is a comment**
d. // This is a comment
a. Alert
b. Confirm
c. Prompt
67. What is the correct syntax for referring to an external script file called : tags.js"?
a. <script src="tags.js">
b. <script name="tags.js">
c. <script href="tags.js">
a. space
b. tabs
c. new lines
a. for
P R E P A R E D GEMECHU.A Page 27
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
b. while
c. foreach
d. forwhile
a. <?
b. ?:
c. >=
d.<>
71. Which of the following attribute is used to include external js code inside your HTML?
a. src
b. href
c. link
d. class
a. var
b. function
c. char
d. const
let d;
P R E P A R E D GEMECHU.A Page 28
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
d = c;
c.greeting = 'BBBootstrap';
console.log(d.message);
a. Hello!
b. undefined
c. ReferenceError
d. BBBoorstrap
let a = 25;
let c = 25;
console.log(a == b);
console.log(b == c);
let message;
messge = {};
console.log(message);
a. undefined
P R E P A R E D GEMECHU.A Page 29
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
b. Reference Error
c. {}
d. None of the above
Check Answer
a. console.message("hello")
b. console.log("hello");
c. log("hello")
d. message("hello");
let x = 5+3+"3";
Console.log(x);
a. 11
b. 8
c. 83
d. None of the above
Correct Answer - 3. 83
P R E P A R E D GEMECHU.A Page 30
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
d. None of these
79. Which of the keyword is used to define the variable in the javascript?
a. var
b. let
c. Both A & B
a. getElementbyId()
b. getElementsByClassName()
c. Both A & B
a. Negative Number
b. Not a Number
c. Both A & B
a. <js>
b. <javascript>
c. <scripting>
d. <script>
P R E P A R E D GEMECHU.A Page 31
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
function myfunc() {
console.log(name);
console.log(age);
myfunc();
a. 1 1 1
b. 3 2 1
c. 3 3 3
d. 1 2 3
const bird = {
size: 'small',
P R E P A R E D GEMECHU.A Page 32
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
};
const mouse = {
name: 'Mickey',
small: true,
};
a. =
b. <
c. >
d. !=
a. Object oriented
b. Object based
c. Functional
d. None of above
Comma(,)
Colon(:)
P R E P A R E D GEMECHU.A Page 33
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
Hyphen(_)
Semicolon(;)
Explanation: JavaScript is a scripting language used along with HTML and CSS to make the
website interactive along. It is used both on the client-side and server-side.
b) JavaScript is Assembly-language
91. Among the given statements, which statement defines closures in JavaScript?
a) JavaScript is a function that is enclosed with references to its inner function scope
c) JavaScript is a function that is enclosed with the object to its inner function scope
P R E P A R E D GEMECHU.A Page 34
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
Explanation: A closure is a function that is enclosed with references to its lexical environment. A
closure allows an inner function to access the scope of an outside function. Closures are formed
every time a function is created in JavaScript, during function creation time.
92. What will be the output of the following JavaScript code snippet?
<p id="demo"></p>
a) error
b) Sanfoundry_ Javascriptmcq
c) undefined
d) Sanfoundry_Javascriptmcq
Explanation: The + operator in javascript acts as a concatenation operator when used with string.
The new string does not have any space between the two added strings.
<p id="demo"></p>
<script>
var js = 10;
js *= 5;
document.getElementById("demo").innerHTML = js;
</script>
P R E P A R E D GEMECHU.A Page 35
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
a) 10
b) 50
c) 5
d) Error
function compare()
int num=2;
char b=2;
if(a==b)
return true;
P R E P A R E D GEMECHU.A Page 36
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
else
return false;
a) false
b) true
c) compilation error
d) runtime error
Explanation: The == in JS convert different types of operands to the same type before making
the comparison. A strict comparison results in true value if the operands are of the same type and
the contents match.
a) Null type
b) Undefined type
c) Number type
Explanation: JavaScript is a dynamic, loosely typed language. Variables in JavaScript aren‟t tied
to any specific value type, and each variable can be assigned and reassigned to values of all the
types.
P R E P A R E D GEMECHU.A Page 37
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025
Explanation: The Client-side JavaScript code is embedded within HTML documents in four
ways :
98. Which of the following object is the main entry point to all client-side JavaScript features
and APIs?
a) Position
b) Window
c) Standard
d) Location
Explanation: All client-side JavaScript features and APIs are accessed through the Window
object. It represents a web browser window or frame, and the identifier window can be used to
refer to it.
function sanfoundry(javascript)
bool ans=true;
P R E P A R E D GEMECHU.A Page 38
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2023
console.log(sanfoundry(ans));
a) Compilation error
b) Runtime error
c) Yes
d) No
Explanation: In javascript, “?” is called the ternary operator which is used for choosing one
choice from the given two choices. It is used instead of if else statement and makes the code
shorter.
function height()
return type;
a) short
b) 123.56
c) tall
d) 190
P R E P A R E D B Y GEMECHU .A Page 39