0% found this document useful (0 votes)
23 views

php mcqs

Uploaded by

absapi09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

php mcqs

Uploaded by

absapi09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PHP MCQ

1) PHP stands for -

1. Hypertext Preprocessor
2. Pretext Hypertext Preprocessor
3. Personal Home Processor
4. None of the above

Answer: (a) Hypertext Preprocessor

Description: PHP stands for Hypertext Preprocessor. PHP is an open-


source, interpreted, and object-oriented scripting language that can be
executed on the server-side. It is well suited for web development.

2) Who is known as the father of PHP?

1. Drek Kolkevi
2. List Barely
3. Rasmus Lerdrof
4. None of the above

Answer: (c) Rasmus Lerdrof

Description: PHP was created by Rasmus Lerdorf in 1994 but appeared in


the market in 1995. PHP 7.4.0 is the latest version of PHP, which was
released on 28 November.

3) Variable name in PHP starts with -

1. ! (Exclamation)
2. $ (Dollar)
3. & (Ampersand)
4. # (Hash)

Answer: (b) $ (Dollar)


Description:

In PHP, a variable is declared using a $ (Dollar) sign followed by the variable


name.

As PHP is a loosely typed language, so we do not need to declare the data


types of the variables. It automatically analyzes the values and makes
conversions to its correct datatype. Variables in PHP are case-sensitive, as an
instance the variables $name and $NAME both are treated as different
variables.

4) Which of the following is the default file extension of PHP?

1. .php
2. .hphp
3. .xml
4. .html

Answer: (a) .php

Description: Generally, a PHP file contains HTML tags and some PHP
scripting code. It is very easy to create a simple PHP example. The programs
in php are saved with the .php extension.

5) Which of the following is not a variable scope in PHP?

1. Extern
2. Local
3. Static
4. Global

Answer: (a) Extern

Description:

The scope of a variable is defined as its range in the program under which it
can be accessed. PHP has three types of variable scopes:
o Local variable
o Global variable
o Static variable

6) Which of the following is correct to add a comment in php?

1. & …… &
2. // ……
3. /* …… */
4. Both (b) and (c)

Answer: (d) Both (b) and (c)

Description:

PHP comments can be used to describe any line of code so that other
developers can understand the code easily. PHP supports single-line and
multi-line comments. There are two ways to use single-line comments in PHP.

o // (C++ style single line comment)


o # (Unix Shell style single line comment)
For multiple lines comment in PHP, we need to enclose all lines within /*
…..*/.

7) Which of the following is used to display the output in PHP?

1. echo
2. write
3. print
4. Both (a) and (c)

Answer: (d) Both (a) and (c)

Description: In PHP, both echo and print are language constructs. Both echo
and print statements can be used with or without parentheses. We can use
these statements to output variables or strings. The echo is a statement,
which is used to display the output. The print is a statement used as an
alternative to echo at many times to display the output.
8) Which of the following is the use of strlen() function in PHP?

1. The strlen() function returns the type of string


2. The strlen() function returns the length of string
3. The strlen() function returns the value of string
4. The strlen() function returns both value and type of string

Answer: (b) The strlen() function returns the length of string

Description: The strlen() function is predefined function of PHP. It is used to


find the length of string or returns the length of a string including all the
whitespaces and special character.

9) Which of the following is used for concatenation in PHP?

1. + (plus)
2. * (Asterisk)
3. . (dot)
4. append()

Answer: (c) . (dot)

Description: In PHP, the . (dot) operator is used for concatenation. Suppose


there are two variables $a and $b, so the statement $a . $b will concatenate
both $a and $b.

10) Which of the following starts with __ (double underscore) in PHP?

1. Inbuilt constants
2. User-defined constants
3. Magic constants
4. Default constants

Answer: (c) Magic constants


Description: Magic constants are the predefined constants in PHP which get
changed on the basis of their use. They start with a double underscore (__)
and end with double underscore. They are similar to other predefined
constants, but as they change their values with the context, they are called
magic constants.

11) Which of the following is the use of strpos() function in PHP?

1. The strpos() function is used to search for the spaces in a string


2. The strpos() function is used to search for a number in a string
3. The strpos() function is used to search for a character/text in a
string
4. The strpos() function is used to search for a capitalize character in
a string

Answer: (c) The strpos() function is used to search for a character/text in a


string

Description: The strops() is in-built function of PHP. It is used to find the


position of the first occurrence of a string inside another string or substring in
a string.

You might also like