What does (int) $_GET['page'] mean in PHP?

后端 未结 9 1356
鱼传尺愫
鱼传尺愫 2021-02-18 23:02

I tried looking up (int) but could only find documentation for the function int() in the PHP manual.

Could someone explain to me what the above

相关标签:
9条回答
  • 2021-02-18 23:29

    What you are looking at there is known as type casting - for more information, see the manual page on type juggling.

    The above piece of code casts (or converts) $_GET['page'] to an integer.

    0 讨论(0)
  • 2021-02-18 23:30

    this kind of syntax (int) is called type casting. Basically it takes the variable following it and tries to force it into being an int

    0 讨论(0)
  • 2021-02-18 23:35

    it casts the variable following it to integer. more info from documentation: http://php.net/manual/en/language.types.type-juggling.php

    Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast.

    The casts allowed are:

    • (int), (integer) - cast to integer
    • (bool), (boolean) - cast to boolean
    • (float), (double), (real) - cast to float
    • (string) - cast to string
    • (array) - cast to array (object) - cast to object
    • (unset) - cast to NULL
    0 讨论(0)
提交回复
热议问题