Programming - PHP

16.

What will be the output of the following PHP code?

<?php
   $array = array (1.1 => '1', 1.2 => '1'); 
   echo count ($array);
?>
Answer

Answer :

Option B

Explanation :


In the associative arrays, only integer numbers and strings can be used as keys of an array. If you use a floating-point number, it will be converted into an integer. In the given question, the index keys 1.1 and 1.2 will be converted to the integer number 0. Due to this, $array will only contain a single element i.e. 0 => '1'.
17.

What will be the output of the following PHP code?

<?php
   $numbers = array(4, "4", "3", 4, 3, "3", 3, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7); 
   echo count(array_unique($numbers));
?>
Answer

Answer :

Option A
18.

What will be the output of the following PHP code?

<?php
   $b = false;
   if($b = true)
     print("true");
   else
     print("false");
?>
Answer

Answer :

Option B

Explanation :


Value true is assigned to the variable x. The result of any assignment expression is the value of the variable following the assignment; hence, "true" will be the output.
19.

What will be the output of the following PHP code?

<?php
   echo (int) ((0.1 + 0.7) * 10);
?>
Answer

Answer :

Option A

Explanation :


The expression ((0.1 + 0.7) * 10) should evaluate to 8. However, the output of the expression in the script evaluates to 7 because the PHP engine stores the value of the expression internally as 7.999999 instead of 8. When the fractional value is converted into an integer, the PHP engine simply truncates the fractional part. When the value is converted to int, PHP simply truncates away the fractional part, resulting in a rather significant error (12.5%, to be exact).
20.

What will be the output of the following PHP code?

<?php
   interface Exam_adda {}
   class_alias('Exam_adda', 'ExamAdda');
   echo interface_exists('ExamAdda') ? 'Yes' : 'No'; 
?>
Answer

Answer :

Option B

Explanation :


class_alias also works for interfaces. The class_alias() function is used to create an alias for a class.
Jump to page number :