constants 修改
This section contains Aptitude Questions and Answers on PHP Constants.
本节包含有关PHP常数的 Aptitude问题和解答。
Constants are just like variables, but its value cannot be changed.
A valid constant name starts with an alphabet or underscore.
There is no need to use the '$' symbol with constants.
All the above
Options:
Correct answer: 4
D
All given statements are correct about the constants in PHP.
常量就像变量一样,但是其值不能更改。
有效的常量名称以字母或下划线开头。
不需要在常量中使用'$'符号。
以上全部
选项:
正确答案:4
d
所有给定的语句对于PHP中的常量都是正确的。
Correct answer: 2
define()
The define() function is used to define a constant in PHP.
正确答案:2
define()
define()函数用于在PHP中定义一个常量。
Correct answer: 1
Yes
Yes, we can create a case-sensitive constant in PHP.
<?php
define("COUNTRY", "INDIA");
echo COUNTRY;
?>
Correct answer: 1
INDIA
The above code will print "INDIA" on the webpage.
<?php
define("COUNTRY", "INDIA");
echo country;
?>
Correct answer: 2
country
The above code will print the "country" on the webpage.
<?php
define("COUNTRY", "INDIA",true);
echo country;
?>
Correct answer: 1
INDIA
The above code will print INDIA on the webpage.
<?php
define("COUNTRY", "INDIA",true);
{
define("COUNTRY", "BHARAT",true);
echo country;
}
?>
Correct answer: 1
INDIA
The above code will print "INDIA" on the webpage.
<?php
define("COUNTRY", "INDIA",true);
{
redefine("COUNTRY", "BHARAT",true);
echo country;
}
?>
Correct answer: 4
Error
The above code will generate an error because redefine() is not an inbuilt function in PHP.
<?php
define("COUNTRIES", {"INDIA","AUSTRALIA","USA"});
echo COUNTRIES[1];
?>
Correct answer: 3
Error
The above code will generate an error because it is not the correct way to define a constant array.
<?php
define("COUNTRIES", ["INDIA","AUSTRALIA","USA"]);
echo COUNTRY[1];
?>
Correct answer: 3
0
The above code will print "0" on the webpage because the COUNTRY constant is not defined.
<?php
define("COUNTRIES", ["INDIA","AUSTRALIA","USA"]);
echo COUNTRIES[1];
?>
Correct answer: 2
AUSTRALIA
The above code will print "AUSTRALIA" on the webpage.
<?php
define("COUNTRY", "INDIA");
function fun()
{
echo COUNTRY;
}
?>
Correct answer: 4
None of the above
The above code will not print anything on the webpage because fun() is not called anywhere in the code.
<?php
define("COUNTRY", "INDIA");
function fun()
{
echo COUNTRY;
}
fun();
?>
Correct answer: 1
INDIA
The above code will print "INDIA" on the webpage.
<?php
define("COUNTRY", "INDIA");
function fun()
{
define("COUNTRY", "USA");
echo COUNTRY;
}
fun();
?>
Correct answer: 1
INDIA
The above code will print "INDIA" on the webpage.
<?php
define("POLICE", 100);
function fun()
{
echo POLICE;
}
fun();
?>
Correct answer: 1
100
The above code will print "100" on the webpage.
翻译自: https://www.includehelp.com/php/constants-aptitude-questions-and-answers.aspx
constants 修改