当前位置: 首页 > 工具软件 > superGlobals > 使用案例 >

PHP Superglobals能力倾向问题与解答

郁吉星
2023-12-01

This section contains Aptitude Questions and Answers on PHP Superglobals.

本节包含有关PHP Superglobals的 Aptitude问答。

1) There are the following statements that are given below, which of them are correct about super-globals in PHP?
  1. The super-global are predefined variables used in PHP.

  2. The super-global variables can be accessed through any function.

  3. The super-global variables can be accessed through any class.

  4. All of the above

Options:

  1. A and B

  2. A and C

  3. B and C

  4. D

Answer & Explanation

Correct answer: 4
D

Explanation:

The super-globals are predefined variables that can be accessed through any function or class with doing anything special in PHP.

1)下面给出了以下语句,其中哪些对于PHP中的超全局变量是正确的?
  1. 超全局变量是PHP中使用的预定义变量。

  2. 可以通过任何函数访问超全局变量。

  3. 可以通过任何类访问超全局变量。

  4. 上述所有的

选项:

  1. A和B

  2. A和C

  3. B和C

  4. d

答案与解释

正确答案:4
d

说明:

超全局变量是预定义的变量,可以通过执行PHP中的任何特殊操作而通过任何函数或类访问。

2) Which of the following are correct superglobal variables used in PHP?
  1. $GLOBALS

  2. $_REQUEST

  3. $_COOKIE

  4. $_SESSION

Options:

  1. A and B

  2. C and D

  3. A, B, and C

  4. A, B, C, and D

Answer & Explanation

Correct answer: 4
A, B, C, and D

Explanation:

There are following superglobal variables used in PHP:

  1. $GLOBALS

  2. $_SERVER

  3. $_REQUEST

  4. $_POST

  5. $_GET

  6. $_FILES

  7. $_ENV

  8. $_COOKIE

  9. $_SESSION

2)以下哪项是PHP中使用的正确的超全局变量?
  1. $全球

  2. $ _REQUEST

  3. $ _COOKIE

  4. $ _SESSION

选项:

  1. A和B

  2. C和D

  3. A,B和C

  4. A,B,C和D

答案与解释

正确答案:4
A,B,C和D

说明:

PHP中使用了以下超全局变量:

  1. $全球

  2. $ _SERVER

  3. $ _REQUEST

  4. $ _POST

  5. $ _GET

  6. $ _FILES

  7. $ _ENV

  8. $ _COOKIE

  9. $ _SESSION

3) PHP stores all global variables in an array called $GLOBALS?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Explanation:

Yes, PHP stores all global variables in an array called $GLOBALS. Here the name of the global variable is used as an index of $GLOBALS. For example, we have $NUM is a global variable then we use $GLOBALS['NUM'] like this.

3)PHP将所有全局变量存储在名为$ GLOBALS的数组中?
  1. 没有

答案与解释

正确答案:1

说明:

是的,PHP将所有全局变量存储在名为$ GLOBALS的数组中。 此处,全局变量的名称用作$ GLOBALS的索引。 例如,我们有$ NUM是一个全局变量,然后像这样使用$ GLOBALS ['NUM'] 。

4) What is the correct output of the given code snippets in PHP?
<?php
$NUM1 = 75;
$NUM2 = 25;
$NUM3 = 0;

function sum()
{
    $NUM1 = 10;
    $NUM2 = 20;

    $GLOBALS['NUM3'] = $GLOBALS['NUM1'] + $GLOBALS['NUM2'];

    $NUM3 = $NUM1 + $NUM2;

    echo $NUM3 . " ";
}

sum();
echo $NUM3 . " ";
?>
  1. 30 30

  2. 30 100

  3. 100 30

  4. 0 30

Answer & Explanation

Correct answer: 2
30 100

Explanation:

The $GLOBALS is used to access global variables anywhere in the program, here we accessed only global variables using $GLOBALS, rest of them are local variable for the function sum(). Then echo statement prints 30 within the function definition and value of $NUM3 outside the function contain the sum of global variables then it prints 100 on the web page.

4)PHP中给定代码段的正确输出是什么?
  1. 30 30

  2. 30 100

  3. 100 30

  4. 0 30

答案与解释

正确答案:2
30 100

说明:

$ GLOBALS用于访问程序中任何位置的全局变量,这里我们仅使用$ GLOBALS访问全局变量,其余的是函数sum()的局部变量。 然后,echo语句在函数定义内打印30,并且函数外部的$ NUM3值包含全局变量的总和,然后在网页上打印100。

5) What is the correct output of the given code snippets in PHP?
<?php
$NUM1 = 75;
$NUM2 = 25;
$NUM3 = 0;

function sum()
{
    $NUM1 = 10;
    $NUM2 = 20;

    $GLOBALS["NUM3"] = $GLOBALS["NUM1"] + $GLOBALS["NUM2"];

    $NUM3 = $NUM1 + $NUM2;

    echo $NUM3 . " ";
}
echo $NUM3;

sum();
?>
  1. 30 30

  2. 30 100

  3. 100 30

  4. 0 30

Answer & Explanation

Correct answer: 4
0 30

Explanation:

Here we print global $NUM3 before calling sum() function, then it will print 0 and then local variable $NUM3 will print 30 inside the sum() function.

Note: We can use a single or double quote to access the global variable in $GLOBALS.

5)PHP中给定代码段的正确输出是什么?
  1. 30 30

  2. 30 100

  3. 100 30

  4. 0 30

答案与解释

正确答案:4
0 30

说明:

这里我们在调用sum()函数之前先打印全局$ NUM3 ,然后它将打印0,然后局部变量$ NUM3将在sum()函数内部打印30。

注意:我们可以使用单引号或双引号来访问$ GLOBALS中的全局变量。

6) There are the following statements that are given below, which of them are correct about $_SERVER in PHP?
  1. The $_SERVER is a superglobal variable, it stores information like server name, headers, and paths.

  2. The $_SERVER is used to get the IP address of the server.

  3. We can get the hostname of the user using $_SERVER variable.

  4. We can get URI of the current web page using $_SERVER variable.

Options:

  1. A and B

  2. C and D

  3. A, B, and C

  4. A, B, C, and D

Answer & Explanation

Correct answer: 4
A, B, C, and D

Explanation:

All given statements are correct about $_SERVER variable.

6)下面给出了以下语句,其中哪些是关于PHP中的$ _SERVER正确的语句?
  1. $ _SERVER是一个超全局变量,它存储诸如服务器名称,标头和路径之类的信息。

  2. $ _SERVER用于获取服务器的IP地址。

  3. 我们可以使用$ _SERVER变量获取用户的主机名。

  4. 我们可以使用$ _SERVER变量获取当前网页的URI。

选项:

  1. A和B

  2. C和D

  3. A,B和C

  4. A,B,C和D

答案与解释

正确答案:4
A,B,C和D

说明:

所有给定的语句关于$ _SERVER变量都是正确的。

7) What is the correct output of the given code snippets in PHP?
<?php
$NUM1 = 75;
$NUM2 = 25;
$NUM3 = 0;

function sum()
{
    $NUM1 = 10;
    $NUM2 = 20;

    $GLOBALS["NUM3"] = $_SERVER["NUM1"] + $GLOBALS["NUM2"];

    $NUM3 = $NUM1 + $NUM2;

    echo $NUM3 . " ";
}

sum();
echo $NUM3;
?>
  1. 30 30

  2. 30 100

  3. 30 25

  4. Syntax error

Answer & Explanation

Correct answer: 3
30 25

Explanation:

The above code will print "30 25" because $_SERVER is not used to access the global variable, but it uses value 0, so that "30 25" printed on the web page.

7)PHP中给定代码段的正确输出是什么?
  1. 30 30

  2. 30 100

  3. 30 25

  4. 语法错误

答案与解释

正确答案:3
30 25

说明:

上面的代码将打印“ 30 25”,因为$ _SERVER不用于访问全局变量,但它使用值0,因此在网页上打印了“ 30 25”。

8) Can we use $GLOBALS in small letters ($globals) to access global variables?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 2
No

Explanation:

No, we cannot use $GLOBALS in small letters ($globals) to access global variables. It will not generate any error but it will not access the global variable.

8)我们可以使用小写的$ GLOBALS($ globals)访问全局变量吗?
  1. 没有

答案与解释

正确答案:2
没有

说明:

不,我们不能使用小写字母( $ globals )使用$ GLOBALS访问全局变量。 它不会产生任何错误,但不会访问全局变量。

9) Can we get the path of the current script using the $_SERVER variable?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Explanation:

Yes, we can get the path of the current script using $_SERVER['SCRIPT_NAME'].

9)我们可以使用$ _SERVER变量获取当前脚本的路径吗?
  1. 没有

答案与解释

正确答案:1

说明:

是的,我们可以使用$ _SERVER ['SCRIPT_NAME']获取当前脚本的路径。

10) Which of the following option is used to get the IP Address of the host server?
  1. $_SERVER['IP_ADDR']

  2. $_SERVER['SERVER_ADDR']

  3. $_SERVER['SERVER_IP_ADDR']

  4. $_SERVER['SERVER_ADDRESS']

Answer & Explanation

Correct answer: 2
$_SERVER['SERVER_ADDR']

Explanation:

The $_SERVER['SERVER_ADDR'] is used to get the IP address where the website is hosted.

10)以下哪个选项用于获取主机服务器的IP地址?
  1. $ _SERVER ['IP_ADDR']

  2. $ _SERVER ['SERVER_ADDR']

  3. $ _SERVER ['SERVER_IP_ADDR']

  4. $ _SERVER ['SERVER_ADDRESS']

答案与解释

正确答案:2
$ _SERVER ['SERVER_ADDR']

说明:

$ _SERVER ['SERVER_ADDR']用于获取网站托管的IP地址。

11) Which of the following option is used to get the name of currently executing script?
  1. $_SERVER['SCR_NAME']

  2. $_SERVER['SCRIPT']

  3. $_SERVER['PHP_SELF']

  4. $_SERVER['PHP_SCRIPT']

Answer & Explanation

Correct answer: 3
$_SERVER['PHP_SELF']

Explanation:

The $_SERVER['PHP_SELF'] is used to get the name of currently executing script.

11)以下哪个选项用于获取当前正在执行的脚本的名称?
  1. $ _SERVER ['SCR_NAME']

  2. $ _SERVER ['SCRIPT']

  3. $ _SERVER ['PHP_SELF']

  4. $ _SERVER ['PHP_SCRIPT']

答案与解释

正确答案:3
$ _SERVER ['PHP_SELF']

说明:

$ _SERVER ['PHP_SELF']用于获取当前正在执行的脚本的名称。

12) Can we access query string using the $_SERVER global variable?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Explanation:

Yes, we can access the query string using $_SERVER['QUERY_STRING'] global variable.

12)我们可以使用$ _SERVER全局变量访问查询字符串吗?
  1. 没有

答案与解释

正确答案:1

说明:

是的,我们可以使用$ _SERVER ['QUERY_STRING']全局变量访问查询字符串。

13) There are the following statements that are given below, which of them are correct about $_REQUEST in PHP?
  1. It is a pre-defined global variable.

  2. It is used to get data after submitting the HTML form.

  3. We can get data without submitting the HTML form.

  4. None of the above

Options:

  1. A and B

  2. A and C

  3. C

  4. D

Answer & Explanation

Correct answer: 1
A and B

Explanation:

The $_REQUEST is a predefined superglobal variable, which is used to get data after submitting the HTML Form.

13)下面给出了以下语句,其中哪些是关于PHP中的$ _REQUEST正确的语句?
  1. 它是一个预定义的全局变量。

  2. 提交HTML表单后,它用于获取数据。

  3. 我们无需提交HTML表单即可获取数据。

  4. 以上都不是

选项:

  1. A和B

  2. A和C

  3. C

  4. d

答案与解释

正确答案:1
A和B

说明:

$ _REQUEST是预定义的超全局变量,用于在提交HTML表单后获取数据。

14) The given code snippet is correct to access data using $_REQUEST in PHP?
<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  value: <input type="text" name="val">
  <input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    $val = $_REQUEST['val'];
}
?>

</body>
</html>
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Explanation:

Yes, in the above code we are accessing the value of the input field using $_REQUEST, this is the proper way to access the values after submitting the HTML form.

14)给定的代码段是否正确,可以在PHP中使用$ _REQUEST访问数据?
  1. 没有

答案与解释

正确答案:1

说明:

是的,在上面的代码中,我们使用$ _REQUEST访问输入字段的值,这是在提交HTML表单之后访问值的正确方法。

15) The $_POST and $_GET are also used to get data after submitting HTML form?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Explanation:

The $_POST and $_GET variables are also used to get data after submitting the HTML form.

15)$ _POST和$ _GET是否也用于提交HTML表单后获取数据?
  1. 没有

答案与解释

正确答案:1

说明:

提交HTML表单后, $ _POST和$ _GET变量也用于获取数据。

翻译自: https://www.includehelp.com/php/superglobals-aptitude-questions-and-answers.aspx

 类似资料: