PHP Math Functions Aptitude Questions and Answers

PHP Math Functions Aptitude: This section contains aptitude questions and answers on PHP Math Functions. By Nidhi Last updated : December 15, 2023

This section contains Aptitude Questions and Answers on PHP Math Functions.

1) What is the correct output of the given code snippets?
<?php
$num1 = - 10;
$num2 = - 20;

$num3 = abs($num1 - $num2);

echo ($num3);
?>
  1. 30
  2. -10
  3. 10
  4. Error

2) What is the correct output of the given code snippets?
<?php
$r = 5;
$area = PY() * $r * $r;
echo ($area);
?>
  1. 78.539816339745
  2. 78
  3. Garbage value
  4. Error

3) Which of the following function is used to convert degree to radian in PHP?
  1. toradian()
  2. torad()
  3. deg2rad()
  4. None of the above

4) Which of the following function is used to convert radian to the degree in PHP?
  1. todegree()
  2. todeg()
  3. rad2deg()
  4. None of the above

5) What is the correct output of the given code snippets?
<?php
$A = 11.2;
$B = 3;

$rem = $A % $B;
echo ($rem);
?>
  1. 2
  2. 2.2
  3. Error
  4. None of the above

6) What is the correct output of the given code snippets?
<?php
$A = 11.2;
$B = 3;

$rem = modf($A, $B);
echo ($rem);
?>
  1. 2
  2. 2.2
  3. Error
  4. None of the above

7) What is the correct output of the given code snippets?
<?php
$A = 11.2;
$B = 3;

$rem = fmod($A, $B);

echo ($rem);
?>
  1. 2
  2. 2.2
  3. Error
  4. None of the above

8) What is the correct output of the given code snippets?
<?php
$num = - 7.8;
echo (floor($num));
?>
  1. -7
  2. -7.5
  3. -8
  4. None of the above

9) What is the correct output of the given code snippets?
<?php
$num = 0.70;
echo (ciel($num));
?>
  1. 1
  2. 0
  3. 0.50
  4. Syntax error

10) What is the correct output of the given code snippets?
<?php
$num = 0.70;
echo (ceil($num));
?>
  1. 1
  2. 0
  3. 0.50
  4. Syntax error

11) Which of the following constants are used in round() function in PHP?
  1. PHP_ROUND_HALF_UP
  2. PHP_ROUND_HALF_DOWN
  3. PHP_ROUND_HALF_EVEN
  4. PHP_ROUND_HALF_ODD

Options:

  1. A and B
  2. A and C
  3. A, B, and C
  4. A, B, C, and D

12) What is the correct output of the given code snippets in PHP?
<?php
echo (round(3.456789, 2));
?>
  1. 3.45
  2. 3.46
  3. Error
  4. None of the above

13) What is the correct output of the given code snippets?
<?php
echo (round(12345678, -2));
?>
  1. 12345600
  2. 12345700
  3. Error
  4. None of the above

14) What is the correct output of the given code snippets?
<?php
echo (round(12.5, 0, PHP_ROUND_HALF_UP));
?>
  1. 12
  2. 13
  3. Error
  4. None of the above

15) What is the correct output of the given code snippets?
<?php
echo (round(12.5, 0, PHP_ROUND_HALF_ODD));
?>
  1. 12
  2. 13
  3. Error
  4. None of the above

16) Which of the following function is used to calculate the power of a number?
  1. power()
  2. pow_number()
  3. pow()
  4. None of the above

17) Which of the following function is used to calculate the square root of a number?
  1. sqrt()
  2. square_root()
  3. squareroot()
  4. None of the above

18) Which of the following function is used to get the natural logarithm of a number based on a specified base?
  1. log()
  2. logarithm()
  3. logs()
  4. None of the above

19) Which of the following functions are used for logarithm in PHP?
  1. log()
  2. log10()
  3. log1p()
  4. log1q()

Options:

  1. A and B
  2. B and C
  3. A, B, and C
  4. A, B, C, and D

20) What is the correct output of the given code snippets in PHP?
<?php
$NUM = max(1, 2, 8, 5, 6);
echo $NUM;
?>
  1. 8
  2. 0
  3. Garbage value
  4. Error

21) What is the correct output of the given code snippets?
<?php
$NUM = max(array(
    1,
    2,
    8,
    5,
    6
));
echo $NUM;
?>
  1. 8
  2. 0
  3. Garbage value
  4. Error

22) What is the correct output of the given code snippets?
<?php
$NUM = max("1,2,8,5,6");
echo $NUM;
?>
  1. 8
  2. 0
  3. Garbage value
  4. Error

23) Which of the following functions are used to generate random numbers in PHP?
  1. rand()
  2. getrandmax()
  3. mt_rand()
  4. xt_rand()

Options:

  1. A and B
  2. C and D
  3. A, B, and C
  4. A, B, C, and D

24) What is the correct output of the given code snippets in PHP?
<?php
$NUM = rand(10, 20);
echo $NUM;
?>
  1. Print a random number that will be within 10 to 20
  2. Error

25) What is the correct output of the given code snippets?
<?php
$NUM = rand();
echo $NUM;
?>
  1. Print a random number
  2. Error

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.