This PHP numbers MCQ quiz has a pool of 25 questions on integers and floats, numeric strings, rounding functions like ceil(), floor() and round(), the % operator, intdiv() and random numbers. It is made for diploma, engineering, BCA and BCS students and freshers preparing for a PHP interview or exam. Every attempt gives you 10 random questions from the pool. Answer them, press Submit, and you will see your score, which answers were right or wrong, and a short explanation for each one.
Numbers are part of PHP’s data types, so if you are new to them, first try our PHP data types MCQ.
Take the PHP Numbers MCQ Quiz
What This Quiz Covers
Most questions ask “What is the output of this code?”, because that is how interviewers test numbers in PHP. The questions come from these topics:
- Integers and floats: which values are int and which are float,
var_dump()output and what happens afterPHP_INT_MAX. - Numeric strings:
is_numeric(),intval(), and what PHP 8 does with strings like"10 apples"or"abc". - Arithmetic:
/,%,intdiv(),fmod(),**,++and operator order. - Rounding and formatting:
ceil(),floor(),round(),(int)casting andnumber_format(). - Floats and random numbers: float precision, and
rand()vsrandom_int().
PHP Numbers: Key Points to Revise
These short notes cover everything the quiz tests. They do not give away the quiz answers, but if you understand them, you can answer every question. The correct answers and explanations appear after you submit the quiz.
int and float: the two number types
PHP has two number types. An int is a whole number such as 42, -7 or 0. A float has a decimal point or an exponent, such as 3.14 or 1.5e3. A value in quotes, like "42", is a string, even if it looks like a number. Use var_dump() to see both the type and the value.
<?php
var_dump(42); // int(42)
var_dump(3.14); // float(3.14)
var_dump("42"); // string(2) "42"
var_dump(PHP_INT_MAX); // int(9223372036854775807) on 64-bitPHP_INT_MAX is the biggest int PHP can store. If a calculation goes beyond it, PHP does not give an error. It changes the result into a float. You can read the full rules in the PHP manual pages on integers and floats.
Numeric strings in PHP 8
When you use a string in maths, PHP tries to turn it into a number. A fully numeric string like "12.5" works without any message. A string that only starts with a number, like "10 apples", uses the number but shows a Warning. A string with no number at the start, like "abc", throws a TypeError in PHP 8. Use is_numeric() to check a value first, for example before using form input in a calculation.
Division, remainder and intdiv()
PHP has four ways to divide, and each one gives a different kind of answer. / returns an int only when the division is exact; otherwise it returns a float. % works on integers and returns the remainder. intdiv() returns only the whole part. fmod() returns the remainder for decimal numbers.
Operator order and the ** operator
** (power) runs before *, / and %, which run before + and -. Most operators of the same level run from left to right, but ** runs from right to left. Use brackets when you are not sure. For ++, remember that $x++ gives the old value and then adds 1, while ++$x adds 1 first and gives the new value.
ceil(), floor(), round() and (int)
These four look similar but behave differently, especially with negative numbers. ceil() always goes up, floor() always goes down, round() goes to the nearest whole number, and (int) or intval() just cuts off the decimal part.
round() also takes a second argument for decimal places, for example round(3.14159, 2) gives 3.14. By default it rounds an exact .5 away from zero. To show a number with commas and fixed decimals, use number_format(), which returns a string.
Why floats are not exact
Floats are stored in binary, and many decimal numbers, like 0.1, cannot be stored exactly. Small errors appear in calculations, so never compare two floats with ==. Round them first, or check that the difference is very small. For money, store amounts in paise (as integers) instead of rupees with decimals.
<?php
$a = 0.1 + 0.2;
echo $a; // 0.3 (looks fine)
var_dump(abs($a - 0.3) < 0.00001); // bool(true), the safe way to compareRandom numbers
rand(min, max) and mt_rand(min, max) give a random int between two numbers and are fine for games or shuffling. For anything related to security, such as OTPs, tokens or passwords, use random_int(min, max), because its numbers cannot be predicted.
How to Score Better Next Time
- Run every code question yourself. Save it as a .php file in XAMPP’s htdocs folder, or use an online PHP sandbox.
- For every rounding question, check whether the number is negative before you answer.
- When you see
var_dump(), think about the type (int, float or string) as well as the value. - Read the explanation of every question you got wrong on the result page, then retake the quiz for a new set of 10.
For a mixed PHP test with basics, arrays and string functions, try our PHP MCQ questions with answers.
Frequently Asked Questions
How many number types are there in PHP?
Two: int (whole numbers) and float (numbers with a decimal point or exponent). A numeric string like "25" is a string, but PHP converts it to a number when you use it in maths.
What is the difference between ceil() and floor() in PHP?
ceil() rounds a number up to the next whole number, and floor() rounds it down. For negative numbers, up means toward zero and down means away from zero. Both return a float.
What is the difference between % and intdiv() in PHP?
% gives the remainder of a division, and intdiv() gives the whole-number result. For 17 and 5, 17 % 5 is 2 and intdiv(17, 5) is 3, because 17 = 5 × 3 + 2.
Where can I see the correct answers?
Press Submit at the end of the quiz. The result page shows your score, the correct answer for every question and a short explanation. The answers are not listed on this page so that you test yourself first.
Conclusion
This PHP numbers MCQ quiz tested the number rules that interviewers use in short output questions: int vs float, numeric strings in PHP 8, % and intdiv(), rounding negative numbers and float precision. If you scored 8 or more out of 10, retake the quiz once or twice to see new questions from the pool of 25. If not, read the key points again, run the code yourself, and try again.
Get one new quiz every week. Join Quiz Lancer on Telegram →
Full-stack developer with 5+ years of experience in PHP, Laravel and JavaScript. I create these quizzes to help students and freshers prepare for web development interviews.



