SlideShare a Scribd company logo
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 1 of 14
PART I - Multiple choice questions focuses on PHP basics and
fundamentals:
1. PHP files have a default file extension of...
A. .html
B. .xml
C. .php
D. .ph
2. A PHP script should start with ... and end with ...
A. <php >
B. <? php ?>
C. <? ?>
D. <?php ?>
Description:
 <?php ?> The standard opening and closing tags
 <? ?> In addition PHP also allows for short open tag and can be enabled
and disabled targeting --enable-short-tags option in the PHP configuration
file php.ini. This is method is not recommended since it is only available if
enabled!
3. Which of the following must be installed on your computer to run and
test PHP script?
A.  Adobe Dreamweaver
B.  PHP
C.  Apache
D.  Notepad++
E.  All of the mentioned.
Description: To test and run PHP script it is required to have PHP and a web server
installed and configured.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 2 of 14
4. We can use ... to comment a single line?
A. /?
B. //
C. #
D. /* */
E. All of the mentioned.
Description: # and // are used and recommended for single line comment, and /* */
can also be used to comment either a single line or multi line.
5. Which of the following PHP statement will store 125 in variable
number?
A. int $number = 125;
B. int number = 125;
C. $number = 125;
D. 125 = $number;
Description: PHP is not a strong typed language like C and Java, therefore, no need
not specify the datatype during variable declaration and initialization.
6. What will be the output of the following PHP code?
<?php
$a = 1;
$b = 2;
echo $a . "+". $b;
?>
A. 3
B. 1+2
C. 1.+.2
D. Error
Description: The dot (.) operator is used to concatenate two or more parts together.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 3 of 14
7. What will be the output of the following PHP code?
<?php
$a = "1";
$b = "2";
echo $a + $b;
?>
A. 3
B. 1+2
C. Error
D. 12
Description: The + operator in PHP is used for mathematical operations; therefore,
the numbers inside the double quotes during the calculation are considered and
parsed as integers and not string.
8. Which of following variables are valid and can be assigned a value
to it?
A. $3hello
B. $_hello
C. $this
D. $This
E. All of the mentioned
Description: Similar as other languages such as Java, C and C++ a variable can't
start with a number in general. The $this is a reference to the current object, and it
is the way to reference an instance of a class from within itself and most commonly
used in object oriented. PHP is a Case Sensitive language, therefore, $This is a valid
variable name.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 4 of 14
9. What will be the output of the following code?
<?php
$name = 'Abdul Rahman';
$anotherName = &$name;
$anotherName = "My name is $anotherName";
echo $anotherName . " " . $name;
?>
A. Error
B. My name is Abdul Rahman Abdul Rahman
C. My name is Abdul Rahman My name is Abdul Rahman
D. My name is Abdul Rahman Abdul Rahman
Description: The statement $anotherName = &$name; will assign the reference and
address of variable $name to $anotherName. This means any modification and
changes to the variable $name will impact $anotherName.
10. What will be the output of the following PHP code?
<?php
$colors = "Red, Green, Blue";
echo $colors[2];
?>
A. Blue
B. Error
C. d
D. Green
Description: PHP treats strings same as arrays, allowing for specific characters to be
accessed via array offset notation. Therefore, index 0 will print character "R", index 1
will print character "e", and index 2 will print character "d".
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 5 of 14
11. What will be the output of the following PHP code?
<?php
$total = "25 students";
$more = 10;
$total = $total + $more;
echo "$total";
?>
A. Error
B. 35 students
C. 35
D. 25 students 10
Description: The + operator in PHP is used for arithmetic operations, therefore, the
value "25" at the beginning of the original $total string is parsed as integer.
However if it begins with anything but a numerical value, the parse result will be
value 0.
12. Which of the below statements is equivalent to $add += $add?
A. $add = $add
B. $add = $add +$add
C. $add = $add + 1
D. $add = $add + $add + 1
Description: The += is shortcut assignment for addition operation, for example, a
+= b is equivalent to a = a + b. The same can be done with subtraction,
multiplication, division, modulus, etc.
13. Which statement will output $name on the screen?
A. echo "$name";
B. echo "$$name";
C. echo "/$name";
D. echo "$name;";
Description: The $ is used to escape the dollar sign ($), therefore, the $name is
treated as a normal string character.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 6 of 14
14. What will be the output of the following code?
<?php
function track() {
static $count = 0;
$count++;
echo $count;
}
track();
track();
track();
?>
A. 123
B. 111
C. 000
D. 012
Description: The static retains its previous value each time the function is called.
Therefore, it makes the function remember the value of the given variable ($count in
the above example) between multiple calls.
15. What will be the output of the following PHP code?
<?php
$name = "Abdul Rahman";
$name .= " Sherzad";
echo $name;
?>
A. Abdul Rahman
B. true
C. false
D. Abdul Rahman Sherzad
Description: The (.=) is a shortcut assignment for concatenation operation. Hence,
the $name equals its current value concatenated with the string " Sherzad".
The statement $name .= " Sherzad"; is equivalent to $name = $name . " Sherzad";
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 7 of 14
16. What will be the output of the following PHP code?
<?php
$a = 5;
$b = 5;
echo ($a === $b);
?>
A. 5 === 5
B. Error
C. 1
D. False
Description: The == operator compares the values of variables for equality and type
casting as necessary. But the === operator checks if the two variables are of the
same type AND have the same value. Hence, variable $a, and variable $b, both are
integers and have same value it prints 1.
17. What will be the output of the following PHP code?
<?php
$age = 10;
echo 'What is his age? n He is $age years old';
?>
A. What is his age? n He is $age years old
B. What is his age?
He is $age years old
C. What is his age? He is 10 years old
D. What is his age?
He is 10 years old
Description: The escape sequence characters and variables when are enclosed
within single quotes '' will not be interpreted when the string is parsed!
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 8 of 14
18. Which of the below symbols is a newline character?
A. r
B. n
C. /n
D. /r
Description: The n escape character in PHP and other most programming
languages is treated as newline character.
19. Which of the conditional statements is/are supported by PHP?
A. if statements
B. if-else statements
C. if-elseif statements
D. switch statements
E. A), B) and C)
F. B), C) and D)
G. All of the mentioned.
Description: PHP supports all the mentioned conditional statements.
20. Which of the looping statements is/are supported by PHP?
A. for loop
B. while loop
C. do-while loop
D. foreach loop
E. A) and B)
F. A), B) and C)
G. All of the mentioned
H. None of the mentioned
Description: PHP supports advanced foreach loop along with other mentioned
common loop statements.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 9 of 14
21. What will be the output of the following PHP code?
<?php
$today = "Monday";
switch ($today) {
case "Saturday":
echo "Beginning of the week. ";
case "Monday":
echo "Middle of the week. ";
case "Thursday":
echo "End of the week. ";
}
?>
A. Error
B. Beginning of the week.
C. Middle of the week.
D. Middle of the week. End of the week.
E. End of the week.
Description: When the break statement is not present, all subsequent case blocks
will execute until a break statement is found.
22. What will be returned when the following PHP code is executed?
<?php
$a = 12;
echo ($a == 12) ? 5 : 1;
?>
A. 12
B. 1
C. Error
D. 5
Description: The above PHP segment used ternary operator. If condition is true then
the part just after the ? operator is executed otherwise the part after : operator.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 10 of 14
23. What will be the output of the following PHP code?
<?php
$users = array("absherzad", "salam", "sattar", "wahid");
for ($x=0; $x < count($users); $x++) {
if ($users[$x] == "absherzad") continue;
echo $users[$x] . " ";
}
?>
A. absherzad
B. salam sattar
C. absherzad salam sattar
D. salam sattar wahid
Description: The continue statement works opposite of break statement, thus,
causes execution of the current loop iteration to end and start at the beginning of
the next iteration.
24. What is the value of $a and $b after the function call?
<?php
function doSomething( &$arg ) {
$return = $arg;
$arg += 1;
return $return;
}
$a = 3;
$b = doSomething( $a );
echo "$a<br>$b";
?>
A. a is 3 and b is 4.
B. a is 4 and b is 3.
C. Both are 3.
D. Both are 4.
Description: Because $arg is passed by reference the variable $a is 4, on the other
hand, because the return value of the function is a copy of the initial value of the
$arg the variable $b is 3.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 11 of 14
25. Who is the father of PHP?
A. Rasmus Lerdorf
B. Willam Makepiece
C. Drek Kolkevi
D. List Barely
PART II – Multiple choice questions focuses on PHP built-in functions,
arrays, filters, regular expression, and file systems:
1. Which one of the following PHP functions can be used to find files?
A. glob()
B. file()
C. fold()
D. get_file()
Description: The glob() function in PHP searches for all the files based on the
matching pattern passed to it, as an example, glob("*.txt") searches all the text files
in the current directory.
2. Which of the following are correct ways of creating an array?
A. state[0] = "West Zone";
B. $state[] = array("West Zone");
C. $state[0] = " West Zone";
D. $state = array("West Zone");
Description: option (A) is not correct because in PHP a variable name must start
with $ symbol. Option (B) is not correct because the square brackets [] are not valid
characters in a variable name.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 12 of 14
3. What will be the output of the following PHP code?
<?php
$fruits = array ("apple", "orange", array ("pear", "mango"),
"banana");
echo (count($fruits, 1));
?>
A. 3
B. 4
C. 5
D. 6
Description: The echo (count($fruits)); statement does not count the items of the
multidimensional arrays, therefore, it prints 4. If the second optional mode
parameter is set to 1, the count() function will recursively count the array, therefore,
the array entity holding "pear" and "mango" items is also counted.
4. What will be the output of the following PHP code?
<?php
$var = 300;
$int_options = array("options" => array ("min_range" => 0,
"max_range" => 256));
if (!filter_var($var, FILTER_VALIDATE_INT, $int_options))
echo("Integer is not valid");
else
echo("Integer is valid");
?>
A. No output is returned
B. Integer is not valid
C. Integer is valid
D. Error
Description: Since the integer value of the variable $var is "300"; and 300 is not in
the specified range, so, the output of the code above will be: "Integer is not valid".
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 13 of 14
5. Which one of the following regular expression matches any string
containing zero or one p?
A. p+
B. p*
C. P?
D. p#
Description:
 The ? (question mark) matches when the preceding character occurs 0 or 1
times only.
 The * (asterisk or star) matches when the preceding character occurs 0 or
more times.
 The + (plus) matches when the preceding character occurs 1 or more times.
6. The filesize() function returns the file size in ___.
A. bits
B. bytes
C. kilobytes
D. gigabytes
Description: The filesize() function returns the size of the file in bytes, or FALSE (and
generates an error of level E_WARNING) in case of an error.
7. Which one of the following function reads a directory into an Array?
A. scandir()
B. readdir()
C. scandirectory()
D. readdirectory()
Description: The scandir() function returns an array consisting of files and directories
found in directory or returns FALSE on error.
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Page 14 of 14
PART III – Explain these easy but yet tricky questions:
1. Explain why the following PHP code returns 3.2 instead of 5:
<?php
$number = 020;
echo $number / 5;
?>
Description: The output of the above code segment is 3.2. This is because in PHP
starting a number with 0 means octal (base 8), therefore, octal 020 is equal 16 in
decimal. Thus, 16 / 5 = 3.2
2. What is the output of the following PHP snippet? Explain why is that
the output?
<?php
echo print(10);
?>
Description: The print always returns 1. Therefore, print statement first print the
value 10, and then return 1 which is then echoed by the echo statement, as a result,
the output is 101.

More Related Content

What's hot

Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZerStd 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Nuzhat Memon
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)
Learnbay Datascience
 
Web technology
Web technologyWeb technology
Web technology
Selvin Josy Bai Somu
 
Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...
James Crone
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
Kuppusamy P
 
Three address code generation
Three address code generationThree address code generation
Three address code generation
Rabin BK
 
Ani mation
Ani mationAni mation
Python Interview questions 2020
Python Interview questions 2020Python Interview questions 2020
Python Interview questions 2020
VigneshVijay21
 
Php introduction
Php introductionPhp introduction
Php introduction
krishnapriya Tadepalli
 
What is Server? (Web Server vs Application Server)
What is Server? (Web Server vs Application Server)What is Server? (Web Server vs Application Server)
What is Server? (Web Server vs Application Server)
Amit Nirala
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
Tech Bikram
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
R.h. Himel
 
CG mini project
CG mini projectCG mini project
CG mini project
Mohammed Dawood
 
Apache ppt
Apache pptApache ppt
Apache ppt
Sanmuga Nathan
 
Software
SoftwareSoftware
Software
fiza1975
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
The HTTP and Web
The HTTP and Web The HTTP and Web
The HTTP and Web
Gouasmia Zakaria
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
SIMONTHOMAS S
 

What's hot (20)

Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZerStd 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
 
Python - gui programming (tkinter)
Python - gui programming (tkinter)Python - gui programming (tkinter)
Python - gui programming (tkinter)
 
Web technology
Web technologyWeb technology
Web technology
 
Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...Looking into the past - feature extraction from historic maps using Python, O...
Looking into the past - feature extraction from historic maps using Python, O...
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Three address code generation
Three address code generationThree address code generation
Three address code generation
 
Ani mation
Ani mationAni mation
Ani mation
 
Python Interview questions 2020
Python Interview questions 2020Python Interview questions 2020
Python Interview questions 2020
 
Php introduction
Php introductionPhp introduction
Php introduction
 
What is Server? (Web Server vs Application Server)
What is Server? (Web Server vs Application Server)What is Server? (Web Server vs Application Server)
What is Server? (Web Server vs Application Server)
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
CG mini project
CG mini projectCG mini project
CG mini project
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Software
SoftwareSoftware
Software
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
The HTTP and Web
The HTTP and Web The HTTP and Web
The HTTP and Web
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
 

Viewers also liked

Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
OXUS 20
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
OXUS 20
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
Lynn Langit
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
OXUS 20
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
Abdul Rahman Sherzad
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
OXUS 20
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
OXUS 20
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
OXUS 20
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
OXUS 20
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
OXUS 20
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
OXUS 20
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
OXUS 20
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
OXUS 20
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
OXUS 20
 
Note - Java Remote Debug
Note - Java Remote DebugNote - Java Remote Debug
Note - Java Remote Debug
boyw165
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
OXUS 20
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Abdul Rahman Sherzad
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
Abdul Rahman Sherzad
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
Som Prakash Rai
 

Viewers also liked (20)

Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
Note - Java Remote Debug
Note - Java Remote DebugNote - Java Remote Debug
Note - Java Remote Debug
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
 

Similar to PHP Basic and Fundamental Questions and Answers with Detail Explanation

06-PHPIntroductionserversicebasicss.pptx
06-PHPIntroductionserversicebasicss.pptx06-PHPIntroductionserversicebasicss.pptx
06-PHPIntroductionserversicebasicss.pptx
20521742
 
Php
PhpPhp
Doc
DocDoc
Php operators
Php operatorsPhp operators
Php operators
Aashiq Kuchey
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
Aftabali702240
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
Geshan Manandhar
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
McSoftsis
 
PHP FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptxPHP FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptx
ShaliniPrabakaran
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Muthuganesh S
 
Php web development
Php web developmentPhp web development
Php web development
Ramesh Gupta
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
Jagat Kothari
 
PHP Reviewer
PHP ReviewerPHP Reviewer
PHP Reviewer
Cecilia Pamfilo
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
C language questions_answers_explanation
C language questions_answers_explanationC language questions_answers_explanation
C language questions_answers_explanation
srinath v
 

Similar to PHP Basic and Fundamental Questions and Answers with Detail Explanation (20)

06-PHPIntroductionserversicebasicss.pptx
06-PHPIntroductionserversicebasicss.pptx06-PHPIntroductionserversicebasicss.pptx
06-PHPIntroductionserversicebasicss.pptx
 
Php
PhpPhp
Php
 
Doc
DocDoc
Doc
 
Php operators
Php operatorsPhp operators
Php operators
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
PHP FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptxPHP FUNCTIONS AND ARRAY.pptx
PHP FUNCTIONS AND ARRAY.pptx
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Php web development
Php web developmentPhp web development
Php web development
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
PHP Reviewer
PHP ReviewerPHP Reviewer
PHP Reviewer
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
C language questions_answers_explanation
C language questions_answers_explanationC language questions_answers_explanation
C language questions_answers_explanation
 

More from OXUS 20

Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
Java Methods
Java MethodsJava Methods
Java Methods
OXUS 20
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
OXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
OXUS 20
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
OXUS 20
 
JAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIJAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART III
OXUS 20
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
OXUS 20
 

More from OXUS 20 (8)

Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
JAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIJAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART III
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
 

Recently uploaded

RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 

Recently uploaded (20)

RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 

PHP Basic and Fundamental Questions and Answers with Detail Explanation

  • 1. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 1 of 14 PART I - Multiple choice questions focuses on PHP basics and fundamentals: 1. PHP files have a default file extension of... A. .html B. .xml C. .php D. .ph 2. A PHP script should start with ... and end with ... A. <php > B. <? php ?> C. <? ?> D. <?php ?> Description:  <?php ?> The standard opening and closing tags  <? ?> In addition PHP also allows for short open tag and can be enabled and disabled targeting --enable-short-tags option in the PHP configuration file php.ini. This is method is not recommended since it is only available if enabled! 3. Which of the following must be installed on your computer to run and test PHP script? A.  Adobe Dreamweaver B.  PHP C.  Apache D.  Notepad++ E.  All of the mentioned. Description: To test and run PHP script it is required to have PHP and a web server installed and configured.
  • 2. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 2 of 14 4. We can use ... to comment a single line? A. /? B. // C. # D. /* */ E. All of the mentioned. Description: # and // are used and recommended for single line comment, and /* */ can also be used to comment either a single line or multi line. 5. Which of the following PHP statement will store 125 in variable number? A. int $number = 125; B. int number = 125; C. $number = 125; D. 125 = $number; Description: PHP is not a strong typed language like C and Java, therefore, no need not specify the datatype during variable declaration and initialization. 6. What will be the output of the following PHP code? <?php $a = 1; $b = 2; echo $a . "+". $b; ?> A. 3 B. 1+2 C. 1.+.2 D. Error Description: The dot (.) operator is used to concatenate two or more parts together.
  • 3. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 3 of 14 7. What will be the output of the following PHP code? <?php $a = "1"; $b = "2"; echo $a + $b; ?> A. 3 B. 1+2 C. Error D. 12 Description: The + operator in PHP is used for mathematical operations; therefore, the numbers inside the double quotes during the calculation are considered and parsed as integers and not string. 8. Which of following variables are valid and can be assigned a value to it? A. $3hello B. $_hello C. $this D. $This E. All of the mentioned Description: Similar as other languages such as Java, C and C++ a variable can't start with a number in general. The $this is a reference to the current object, and it is the way to reference an instance of a class from within itself and most commonly used in object oriented. PHP is a Case Sensitive language, therefore, $This is a valid variable name.
  • 4. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 4 of 14 9. What will be the output of the following code? <?php $name = 'Abdul Rahman'; $anotherName = &$name; $anotherName = "My name is $anotherName"; echo $anotherName . " " . $name; ?> A. Error B. My name is Abdul Rahman Abdul Rahman C. My name is Abdul Rahman My name is Abdul Rahman D. My name is Abdul Rahman Abdul Rahman Description: The statement $anotherName = &$name; will assign the reference and address of variable $name to $anotherName. This means any modification and changes to the variable $name will impact $anotherName. 10. What will be the output of the following PHP code? <?php $colors = "Red, Green, Blue"; echo $colors[2]; ?> A. Blue B. Error C. d D. Green Description: PHP treats strings same as arrays, allowing for specific characters to be accessed via array offset notation. Therefore, index 0 will print character "R", index 1 will print character "e", and index 2 will print character "d".
  • 5. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 5 of 14 11. What will be the output of the following PHP code? <?php $total = "25 students"; $more = 10; $total = $total + $more; echo "$total"; ?> A. Error B. 35 students C. 35 D. 25 students 10 Description: The + operator in PHP is used for arithmetic operations, therefore, the value "25" at the beginning of the original $total string is parsed as integer. However if it begins with anything but a numerical value, the parse result will be value 0. 12. Which of the below statements is equivalent to $add += $add? A. $add = $add B. $add = $add +$add C. $add = $add + 1 D. $add = $add + $add + 1 Description: The += is shortcut assignment for addition operation, for example, a += b is equivalent to a = a + b. The same can be done with subtraction, multiplication, division, modulus, etc. 13. Which statement will output $name on the screen? A. echo "$name"; B. echo "$$name"; C. echo "/$name"; D. echo "$name;"; Description: The $ is used to escape the dollar sign ($), therefore, the $name is treated as a normal string character.
  • 6. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 6 of 14 14. What will be the output of the following code? <?php function track() { static $count = 0; $count++; echo $count; } track(); track(); track(); ?> A. 123 B. 111 C. 000 D. 012 Description: The static retains its previous value each time the function is called. Therefore, it makes the function remember the value of the given variable ($count in the above example) between multiple calls. 15. What will be the output of the following PHP code? <?php $name = "Abdul Rahman"; $name .= " Sherzad"; echo $name; ?> A. Abdul Rahman B. true C. false D. Abdul Rahman Sherzad Description: The (.=) is a shortcut assignment for concatenation operation. Hence, the $name equals its current value concatenated with the string " Sherzad". The statement $name .= " Sherzad"; is equivalent to $name = $name . " Sherzad";
  • 7. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 7 of 14 16. What will be the output of the following PHP code? <?php $a = 5; $b = 5; echo ($a === $b); ?> A. 5 === 5 B. Error C. 1 D. False Description: The == operator compares the values of variables for equality and type casting as necessary. But the === operator checks if the two variables are of the same type AND have the same value. Hence, variable $a, and variable $b, both are integers and have same value it prints 1. 17. What will be the output of the following PHP code? <?php $age = 10; echo 'What is his age? n He is $age years old'; ?> A. What is his age? n He is $age years old B. What is his age? He is $age years old C. What is his age? He is 10 years old D. What is his age? He is 10 years old Description: The escape sequence characters and variables when are enclosed within single quotes '' will not be interpreted when the string is parsed!
  • 8. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 8 of 14 18. Which of the below symbols is a newline character? A. r B. n C. /n D. /r Description: The n escape character in PHP and other most programming languages is treated as newline character. 19. Which of the conditional statements is/are supported by PHP? A. if statements B. if-else statements C. if-elseif statements D. switch statements E. A), B) and C) F. B), C) and D) G. All of the mentioned. Description: PHP supports all the mentioned conditional statements. 20. Which of the looping statements is/are supported by PHP? A. for loop B. while loop C. do-while loop D. foreach loop E. A) and B) F. A), B) and C) G. All of the mentioned H. None of the mentioned Description: PHP supports advanced foreach loop along with other mentioned common loop statements.
  • 9. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 9 of 14 21. What will be the output of the following PHP code? <?php $today = "Monday"; switch ($today) { case "Saturday": echo "Beginning of the week. "; case "Monday": echo "Middle of the week. "; case "Thursday": echo "End of the week. "; } ?> A. Error B. Beginning of the week. C. Middle of the week. D. Middle of the week. End of the week. E. End of the week. Description: When the break statement is not present, all subsequent case blocks will execute until a break statement is found. 22. What will be returned when the following PHP code is executed? <?php $a = 12; echo ($a == 12) ? 5 : 1; ?> A. 12 B. 1 C. Error D. 5 Description: The above PHP segment used ternary operator. If condition is true then the part just after the ? operator is executed otherwise the part after : operator.
  • 10. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 10 of 14 23. What will be the output of the following PHP code? <?php $users = array("absherzad", "salam", "sattar", "wahid"); for ($x=0; $x < count($users); $x++) { if ($users[$x] == "absherzad") continue; echo $users[$x] . " "; } ?> A. absherzad B. salam sattar C. absherzad salam sattar D. salam sattar wahid Description: The continue statement works opposite of break statement, thus, causes execution of the current loop iteration to end and start at the beginning of the next iteration. 24. What is the value of $a and $b after the function call? <?php function doSomething( &$arg ) { $return = $arg; $arg += 1; return $return; } $a = 3; $b = doSomething( $a ); echo "$a<br>$b"; ?> A. a is 3 and b is 4. B. a is 4 and b is 3. C. Both are 3. D. Both are 4. Description: Because $arg is passed by reference the variable $a is 4, on the other hand, because the return value of the function is a copy of the initial value of the $arg the variable $b is 3.
  • 11. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 11 of 14 25. Who is the father of PHP? A. Rasmus Lerdorf B. Willam Makepiece C. Drek Kolkevi D. List Barely PART II – Multiple choice questions focuses on PHP built-in functions, arrays, filters, regular expression, and file systems: 1. Which one of the following PHP functions can be used to find files? A. glob() B. file() C. fold() D. get_file() Description: The glob() function in PHP searches for all the files based on the matching pattern passed to it, as an example, glob("*.txt") searches all the text files in the current directory. 2. Which of the following are correct ways of creating an array? A. state[0] = "West Zone"; B. $state[] = array("West Zone"); C. $state[0] = " West Zone"; D. $state = array("West Zone"); Description: option (A) is not correct because in PHP a variable name must start with $ symbol. Option (B) is not correct because the square brackets [] are not valid characters in a variable name.
  • 12. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 12 of 14 3. What will be the output of the following PHP code? <?php $fruits = array ("apple", "orange", array ("pear", "mango"), "banana"); echo (count($fruits, 1)); ?> A. 3 B. 4 C. 5 D. 6 Description: The echo (count($fruits)); statement does not count the items of the multidimensional arrays, therefore, it prints 4. If the second optional mode parameter is set to 1, the count() function will recursively count the array, therefore, the array entity holding "pear" and "mango" items is also counted. 4. What will be the output of the following PHP code? <?php $var = 300; $int_options = array("options" => array ("min_range" => 0, "max_range" => 256)); if (!filter_var($var, FILTER_VALIDATE_INT, $int_options)) echo("Integer is not valid"); else echo("Integer is valid"); ?> A. No output is returned B. Integer is not valid C. Integer is valid D. Error Description: Since the integer value of the variable $var is "300"; and 300 is not in the specified range, so, the output of the code above will be: "Integer is not valid".
  • 13. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 13 of 14 5. Which one of the following regular expression matches any string containing zero or one p? A. p+ B. p* C. P? D. p# Description:  The ? (question mark) matches when the preceding character occurs 0 or 1 times only.  The * (asterisk or star) matches when the preceding character occurs 0 or more times.  The + (plus) matches when the preceding character occurs 1 or more times. 6. The filesize() function returns the file size in ___. A. bits B. bytes C. kilobytes D. gigabytes Description: The filesize() function returns the size of the file in bytes, or FALSE (and generates an error of level E_WARNING) in case of an error. 7. Which one of the following function reads a directory into an Array? A. scandir() B. readdir() C. scandirectory() D. readdirectory() Description: The scandir() function returns an array consisting of files and directories found in directory or returns FALSE on error.
  • 14. PHP Basic and Fundamental Questions and Answers with Detail Explanation Page 14 of 14 PART III – Explain these easy but yet tricky questions: 1. Explain why the following PHP code returns 3.2 instead of 5: <?php $number = 020; echo $number / 5; ?> Description: The output of the above code segment is 3.2. This is because in PHP starting a number with 0 means octal (base 8), therefore, octal 020 is equal 16 in decimal. Thus, 16 / 5 = 3.2 2. What is the output of the following PHP snippet? Explain why is that the output? <?php echo print(10); ?> Description: The print always returns 1. Therefore, print statement first print the value 10, and then return 1 which is then echoed by the echo statement, as a result, the output is 101.