search

Home  >  Q&A  >  body text

php $t1 $t2

< /p>

As shown in the figure:
I did not declare the two variables $t1 and $t2
Why can it be used? No error is reported, and the manual doesn't say why

淡淡烟草味淡淡烟草味2811 days ago569

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:11:14

    First picture:

    The manual says very clearly, assign the values ​​in the array to a set of variables.

    Your question:

    As shown in the picture:
    I did not declare the $t1 and $t2 variables
    Why can it be used? No error is reported, and the manual doesn’t say why

    So I understand that your question means two things:

    1. No variable declared

    2. No error will be reported when using undeclared variables

    In response to the first point, PHP is a weakly typed language, and variables do not need to be declared before use. You can also understand that variables are declared (initialized) at the same time when assigning values ​​to variables.
    Well, the usage manual of list has made it very clear, Assign the values ​​in the array to a set of variables, that is, the assignment is successful after you run list($t1, $t2) = explode(' ', microtime())的时候,已经给 $t1$t2.

    As for the second point, for undeclared variables (that is, variables that are not initialized), of course an error will be reported if used.
    You can try directly echo $undefined;$undefined第一次出现在这里,不出意外情况,肯定报个 Notice level errors (please set the error level correctly and display the error first).

    So your second question is not that you used an undeclared variable without reporting an error, but that you used a variable that list() has already been assigned for you.

    Hope to adopt it! Thanks.

    ======== Update ======

    The above picture also marks the difference in the use of list() in the PHP version, please pay attention when using it!

    reply
    0
  • 某草草

    某草草2017-05-16 13:11:14

    The function of the

    list function is to assign the values ​​​​in the array to some variables, such as:

    list($a, $b, $c) = array(1, 2, 3);

    Then the value of $a is 1, the values ​​of $b and $c are 2 and 3

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:11:14

    list($t1,$t2)

    The above means to set the key values ​​of the array on the right to $t1 $t2 in turn

    reply
    0
  • Cancelreply