PHP Numbers | 7+ Expert Logical MCQ Questions on PHP Numbers

PHP Numbers

As an experienced developer, let me know you, PHP Numbers are a very important concept that must know who want to become a backend or full stack developer. There are 3 numeric types of Numbers in PHP. Let’s see which they are.

Join to Become PHP Web Developer - Future Scope Career Guidance

WhatsApp Group Join Now
Telegram Group Join Now
Follow On Instagram Follow Us

Numeric Types in PHP Numbers

  1. Integer
    An integer is a number without any decimal part. For example, 2, 20, 200, and 2000 are Integer numbers because they don’t have a decimal point in a number.
  2. Float
    A float is a number with a decimal part. For example, 2.0, 2.0, 20.0, and 200.0 are Float numbers because they have a decimal point in a number.
  3. Number String
    A numeric string is a string that contains numbers. PHP can automatically convert numeric strings to actual numbers when performing arithmetic operations. Example: $numString = “1989”;

Beginner-Level MCQ Questions on PHP Numbers

Which of the following is a valid integer in PHP?

A. 42
B. 42.5
C. “42”
D. 0x42

Correct Answer: A – 42


What function is used to round a float to the nearest integer in PHP?

A. ceil()
B. floor()
C. round()
D. truncate()

Correct Answer: C – round()


What is the output of ceil(4.3) in PHP?

A. 4
B. 5
C. 4.3
D. 4.5

Correct Answer A – 4


Which function returns the absolute value of a number in PHP?

A. abs()
B. fabs()
C. absolute()
D. mag()

Correct Answer A – abs()


Intermediate Level MCQ Questions on PHP Numbers

What will be the output of echo (int)3.9; in PHP?

A. 3
B. 4
C. 3.9
D. Error

Correct Answer A – 3


How would you generate a random integer between 1 and 100 in PHP?

A. random(1, 100)
B. rand(1, 100)
C. random_int(1, 100)
D. mt_rand(1, 100)

Correct Answer B – rand(1, 100)


What will be the result of pow(2, 3) in PHP?

A. 6
B. 8
C. 9
D. 16

Correct Answer B – 8


Advanced Level MCQ Questions on PHP Numbers

How can you calculate the natural logarithm of a number in PHP?

A. log10()
B. log()
C. ln()
D. exp()

Correct Answer B – log()


Which PHP function will return the remainder of a division?

A. mod()
B. remainder()
C. div()
D. %

Correct Answer D – %


What is the output of round(7.25, 1) in PHP?

A. 7
B. 7.3
C. 7.2
D. 7.25

Correct Answer B – 7.3


How do you find the base-10 logarithm of a number in PHP?

A. log10()
B. log()
C. logb()
D. logten()

Correct Answer A – log10()


What will be the output of intval(42.8) in PHP?

A. 42
B. 43
C. 42.8
D. Error

Correct Answer A – 42


Logical MCQ Questions on PHP Numbers

What will be the output of the following code?

A. 1
B. 2
C. 3
D. 0

Correct Answer B – 2


Given the following code, what will be the output?

A. 14
B. 15
C. 16
D. 13

Correct Answer C – 16


What will the following code snippet output?

A. 500
B. 1000
C. 9765625
D. 50

Correct Answer C – 9765625


Logical MCQ in PHP Numbers
Logical MCQ in PHP Numbers

13+ Excellence MCQ on Data Types in PHP


What will the following code output?

A. 12
B. 15
C. 16
D. 14

Correct Answer B – 15

Let me explain to you why the answer is 15.

$a is set to 15.

$b is set to 4.

First, the division $a / $b is evaluated: $a / $b = 15 / 4 = 3.75; value of $b is 4.

Next, multiply this result by $b. ($a / $b) * $b 3.75 * 4 = 15.0;

Type Casting to Integer:

The result of the multiplication is 15.0.

Casting 15.0 to an integer using (int) results in 15.


What will the following code output?

A. -4
B. -3
C. 3
D. 4

Correct Answer B – -3

Step-by-Step Explanation
Initial Value:
$number is set to -3.75.

Using ceil() Function: The ceil() function in PHP rounds a number up to the nearest integer.
For negative numbers, “up” means towards zero. Therefore, ceil(-3.75) will round to the nearest integer greater than or equal to -3.75, which is -3.


Given the code below, what will be the output?

A. 128
B. 162
C. 512
D. 1024

Correct Answer B – 162

Explanation:

The exponentiation operation has higher precedence than multiplication.

First, evaluate $b ** $c

$b ** $c = 3 ** 4 = 3 * 3 * 3 * 3 = 81;

Next, multiply the result by $a

$a * 81 = 2 * 81 = 162;


What will the following code snippet output?

A. 10
B. 20
C. 10 apples
D. Error

Correct Answer B – 20

Explanation: Type Conversion in PHP

PHP will attempt to convert strings to numbers when performing arithmetic operations. If a string starts with a numeric value, PHP will use that numeric value and ignore the rest of the string.

Initial Values:

$a is set to 10.
$b is set to “10 apples”.

String to Number Conversion:

When adding $a and $b, PHP will convert the string “10 apples” to the integer 10.

Arithmetic Operation:

The addition operation will be performed:

$sum = 10 + 10;

The result of the addition is 20.


What will be the output of this code?

A. 4
B. 8
C. 16
D. 2

Correct Answer A – 4

Explanation: sqrt means Square Root. Square Root of 16 is 4.


What will the following code output?

A. 7
B. 7.6
C. 8
D. 6

Correct Answer C – 8

Explanation: $x = 5.5 and $y = 2.1 $x + $y means 5.5 + 2.1 = 7.6

Round (7.6), round() function to round the result to the nearest integer. round(7.6) = 8;


Follow us on Social Platforms for Updated Knowledge

Follow Quiz Lancer Instagram, WhatsApp, Facebook, LinkedInTelegram Channel to solve daily MCQ on PHP Numbers. We share important interview questions which are asked in the interview. Most of the students get good values from this channel and got selected as a developer.


85 / 100
Scroll to Top