PHP Constants Aptitude Questions and Answers

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

This section contains Aptitude Questions and Answers on PHP Constants.

1) There are the following statements that are given below, which of them are correct about constants in PHP?
  1. Constants are just like variables, but its value cannot be changed.
  2. A valid constant name starts with an alphabet or underscore.
  3. There is no need to use the '$' symbol with constants.
  4. All the above

Options:

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

2) Which of the following function is used to define a constant in PHP?
  1. defconst()
  2. define()
  3. const()
  4. def()

3) Can we create a case-sensitive constant in PHP?
  1. Yes
  2. No

4) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA");
echo COUNTRY;
?>
  1. INDIA
  2. COUNTRY
  3. Garbage value
  4. Error

5) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA");
echo country;
?>
  1. INDIA
  2. country
  3. Garbage value
  4. Error

6) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA", true);
echo country;
?>
  1. INDIA
  2. country
  3. Garbage value
  4. Error

7) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA", true);
define("COUNTRY", "BHARAT", true);
echo country;
?>
  1. INDIA
  2. country
  3. BHARAT
  4. Error

8) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA", true);
redefine("COUNTRY", "BHARAT", true);
echo country;
?>
  1. INDIA
  2. country
  3. BHARAT
  4. Error

9) What is the correct output of the given code snippets?
<?php
define("COUNTRIES", {"INDIA","AUSTRALIA","USA"});
echo COUNTRIES[1];    
?>
  1. INDIA
  2. AUSTRALIA
  3. Error
  4. Garbage value

10) What is the correct output of the given code snippets?
<?php
define("COUNTRIES", ["INDIA", "AUSTRALIA", "USA"]);
echo COUNTRY[1];
?>
  1. INDIA
  2. AUSTRALIA
  3. 0
  4. Error

11) What is the correct output of the given code snippets?
<?php
define("COUNTRIES", ["INDIA", "AUSTRALIA", "USA"]);
echo COUNTRIES[1];
?>
  1. INDIA
  2. AUSTRALIA
  3. 0
  4. Error

12) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA");

function fun()
{
    echo COUNTRY;
}
?>
  1. INDIA
  2. 0
  3. Error
  4. None of the above

13) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA");

function fun()
{
    echo COUNTRY;
}

fun();
?>
  1. INDIA
  2. 0
  3. Error
  4. None of the above

14) What is the correct output of the given code snippets?
<?php
define("COUNTRY", "INDIA");

function fun()
{
    define("COUNTRY", "USA");
    echo COUNTRY;
}

fun();
?>
  1. INDIA
  2. USA
  3. Error
  4. None of the above

15) What is the correct output of the given code snippets?
<?php
define("POLICE", 100);

function fun()
{
    echo POLICE;
}

fun();
?>
  1. 100
  2. POLICE
  3. Error
  4. None of the above

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





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