English 中文(简体)
PHP指的是什么(int)美元?
原标题:What does (int) $_GET[ page ] mean in PHP?
  • 时间:2011-10-29 20:41:28
  •  标签:
  • php
  • int

我尝试研究<代码>(int),但只能找到PHP手册中的功能int()。

难道有人能向我解释上述法典是什么,以及它是如何运作的?

最佳回答

它将(至少是尝试)变数的任何价值都转换为ger。 如果有任何信件等,它就将改为0。

<?php

$var =  1a ;

echo $var;               // 1a
echo (int) $var;     //1

$var2 =  a2 ;
echo $var2;           //a2
echo (int) $var2;     // 0

?>

问题回答

可在

<代码>(int)将某一数值转换为单位。

<?php
$test = "1";
echo gettype((int)$test);
?>

$ php test.php
integer

简单的例子将使你理解:

var_dump((int)8);
var_dump((int)"8");
var_dump((int)"6a6");

var_dump((int)"a6");

var_dump((int)8.9);
var_dump((int)"8.9");
var_dump((int)"6.4a6");

结果:

int(8)
int(8)
int(6)

int(0)

int(8)
int(8)
int(6)

在PHP中,(int)将具有以下价值:int

例:

php > var_dump((int) "5");
int(5)

I believe the syntax was borrowed from C.

这类合成物<代码>(int)称为打字。 从根本上说,它采用了随之产生的变量,并试图将其变成一个<条码>。

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.

允许的投票是:

  • (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




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...