ExamVeda
Login
Home
31
What will be the output of the following PHP code ?
<?php
$one = "one";
$two = "two";
print("$one$two");
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
This is same as the echo statement.
32
What will be the output of the following PHP code ?
<?php
$one = "one";
$two = "two";
print($one==$two);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Since we are equating two unequal strings we do not get any output.
33
What will be the output of the following PHP code ?
<?php
$one = "one";
$two = "one";
print($one == $two);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Since both the strings are equal the result 1 is printed on the screen.
34
What will be the output of the following PHP code ?
<?php
print("this"."was"."a"."bad"."idea");
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
You can use the dot operator like in echo but you can not use the comma operator to do the same.
35
What will be the output of the following PHP code ?
<?php
define("GREETING", "PHP is a scripting language");
echo $GREETING;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Constants do not need a $ before them, they are referenced by their variable names itself.
36
What will be the output of the following PHP code ?
<?php
class Constants
{
    define('MIN_VALUE', '0.0');  
    define('MAX_VALUE', '1.0');  
    public static function getMinValue()
    {
        return self::MIN_VALUE;
    }
    public static function getMaxValue()
    {
        return self::MAX_VALUE;
    }
}
echo Constants::getMinValue();
echo Constants::getMaxValue();
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
In a class constants should be defined const MIN_VALUE = 0.0;const MAX_VALUE = 1.0; instead.
37
What will be the output of the following PHP code ?
<?php
define("__LINE__", "PHP is a scripting language");
echo __LINE__;
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
__LINE__ is a magical constant that gives the current line number and cannot be used a variable/constant name.
38
What will be the output of the following PHP code ?
<?php
define('IF', 42); 
echo "IF: ", IF;
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
Keyword like IF cannot be used as constant names.
39
What will be the output of the following PHP code ?
<?php
define("NEW_GOOD_NAME_CONSTANT", "I have a value");
define("OLD_BAD_NAME_CONSTANT", NEW_GOOD_NAME_CONSTANT);
 
echo NEW_GOOD_NAME_CONSTANT;
echo OLD_BAD_NAME_CONSTANT; 
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Constants can be set as values for other constants.
40
What will be the output of the following PHP code ?
<?php
define("VAR_NAME","test"); 
${VAR_NAME} = "value"; 
echo VAR_NAME;
echo ${VAR_NAME}; 
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
${VAR_NAME} creates a new variable which is not same as VAR_NAME.