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
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'.
Answer :
Option BExplanation :
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 A18.
What will be the output of the following PHP code?
<?php $b = false; if($b = true) print("true"); else print("false"); ?>
Answer
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.
Answer :
Option BExplanation :
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
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).
Answer :
Option AExplanation :
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
class_alias also works for interfaces. The class_alias() function is used to create an alias for a class.
Answer :
Option BExplanation :
class_alias also works for interfaces. The class_alias() function is used to create an alias for a class.
Jump to page number :