我尝试研究<代码>(int),但只能找到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)称为打字。 从根本上说,它采用了随之产生的变量,并试图将其变成一个<条码>。
(int)与(t)相同。
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
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 ...
<?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 = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
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 ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
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? 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 ...