PHP 支持 8 种原始数据类型。
四种标量类型:
boolean(布尔型)false 和 true
只有两个取值
integer(整型)
也就是非小数
float(浮点型,也称作 double(取值范围比float小))
小数
string(字符串)
两种复合类型:
array(数组)
object(对象)
最后是两种特殊类型:
resource(资源)
NULL(无类型)
为了确保代码的易读性,本手册还介绍了一些伪类型:
mixed(混合类型)
number(数字类型)
callback(回调类型)
更详细的说明LZ可以百度搜索:php数据类型 会有很详细的介绍
is_array — 检测变量是否是数组
is_bool — 检测变量是否是布尔型
is_callable — 检测参数是否为合法的可调用结构
is_double — is_float 的别名
is_float — 检测变量是否是浮点型
is_int — 检测变量是否是整数
is_integer — is_int 的别名
is_iterable — Verify that the contents of a variable is an iterable value
is_long — is_int 的别名
is_null — 检测变量是否为 NULL
is_numeric — 检测变量是否为数字或数字字符串
is_object — 检测变量是否是一个对象
is_real — is_float 的别名
is_resource — 检测变量是否为资源类型
is_scalar — 检测变量是否是一个标量
is_string — 检测变量是否是字符串
变量名 =》 zval
变量值 =》zend_value
问题:
引用计数
变量传递,变量赋值
变量的基础结构
变量值:zend_value
typedef union _zend_value {
zend_long lval; / long value /
double dval; / double value /
zend_refcounted counted;
zend_string str;
zend_array arr;
zend_object obj;
zend_resource res;
zend_reference ref;
zend_ast_ref ast;
zval zv;
void ptr;
zend_class_entry ce;
zend_function func;
struct {
uint32_t w1;
uint32_t w2;
} ww;
} zend_value;
变量名:_zval
typedef struct _zval_struct zval;
struct _zval_struct {
zend_value value; / value /
union {
struct {
ZEND_ENDIAN_LOHI_4(
zend_uchar type, / active type /
zend_uchar type_flags,
zend_uchar const_flags,
zend_uchar reserved) / call info for EX(This) /
} v;
uint32_t type_info;
} u1;
union {
uint32_t var_flags;
uint32_t next; / hash collision chain /
uint32_t cache_slot; / literal cache slot /
uint32_t lineno; / line number (for ast nodes) /
uint32_t num_args; / arguments number for EX(This) /
uint32_t fe_pos; / foreach position /
uint32_t fe_iter_idx; / foreach iterator index /
} u2;
};
变量类型type
/ regular data types /
#define IS_UNDEF 0
#define IS_NULL 1
#define IS_FALSE 2
#define IS_TRUE 3
#define IS_LONG 4
#define IS_DOUBLE 5
#define IS_STRING 6
#define IS_ARRAY 7
#define IS_OBJECT 8
#define IS_RESOURCE 9
#define IS_REFERENCE 10
/ constant expressions /
#define IS_CONSTANT 11
#define IS_CONSTANT_AST 12
/ fake types /
#define _IS_BOOL 13
#define IS_CALLABLE 14
/ internal types /
#define IS_INDIRECT 15
#define IS_PTR 17
true 和 flase 没有zend_value 结构, 直接通过type来区分,zend_long和double的变量指直接存储在_zend_value中,不需要额外的value指针。
$test1 = 123;
$test2 = 123;
function get_variable_name(&$var, $scope = NULL) {
if (NULL == $scope) {
$scope = $GLOBALS;
}
$tmp = $var;
$var = "tmp_exists_" mt_rand();
$name = array_search($var, $scope, TRUE);
$var = $tmp;
return $name;
}
//>
你这样是不行的, 因为action是不传值的, 你要透过form来传值要用 hidde box
<input type="hidden" name="tid" value="351577"> 这样再用php 的$_GET['tid'] 就可以
如果你一定要用action来传值, 你需要用ajax 来做, 没必要那么麻烦
<php
function vname(&$var, $scope=false, $prefix='unique', $suffix='value')
{
if($scope) $vals = $scope;
else $vals = $GLOBALS;
$old = $var;
$var = $new = $prefixrand()$suffix;
$vname = FALSE;
foreach($vals as $key => $val) {
if($val === $new) $vname = $key;
}
$var = $old;
return $vname;
}
echo "\$变量名="vname($变量名);
>
输出结果: $变量名=变量名
以上就是关于PHP中变量类型的问题全部的内容,包括:PHP中变量类型的问题、php怎么判断数据类型、PHP变量名、变量值、类型等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)