Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php查找整数/字符的大小(以字节为单位)?_Php - Fatal编程技术网

如何使用php查找整数/字符的大小(以字节为单位)?

如何使用php查找整数/字符的大小(以字节为单位)?,php,Php,可能重复: 我需要使用php查找int/char或数组的大小(以字节为单位)。我认为在php中进行内存管理是可能的。IIRC,php不使用整数类型,但对所有内容都使用浮点。@Wug:不,php有单独的Int和Float类型。其他类型(例如Real)是Float的假名。那么必须是另一种语言。我在想什么。。。编辑:我想是javascript。看看你试过了吗?因为这行不通!如果我输入$temp=str_repeat(),它的计数是正确的,但如果我只是复制它,它会得到负值吗?用php优化?或者为什么?

可能重复:


我需要使用php查找int/char或数组的大小(以字节为单位)。我认为在php中进行内存管理是可能的。

IIRC,php不使用整数类型,但对所有内容都使用浮点。@Wug:不,php有单独的Int和Float类型。其他类型(例如Real)是Float的假名。那么必须是另一种语言。我在想什么。。。编辑:我想是javascript。看看你试过了吗?因为这行不通!如果我输入$temp=str_repeat(),它的计数是正确的,但如果我只是复制它,它会得到负值吗?用php优化?或者为什么?
$temp=$variable\u to\u test
被称为浅层复制,在修改
$temp
之前,它实际上不会在内存中占有一席之地。您可以采用两种方法之一:1-
$temp=$variable\u to\u test$温度=''2-
$temp=unserialize(serialize($variable_to_test))
好的,感谢您的解释,在上面的代码中添加一个包含空字符串的concatation,现在它得到了更高的值(可能是正确的)
/* load before whit a value */
$before = memory_get_usage(FALSE);

/* make sure $temp dosn't have a content before */
$temp = NULL;

/* calculate current usage */
$before = memory_get_usage(FALSE);

/* copy the content to a nex varibale */
$temp = $variable_to_test . '';

/* calculate the new usage */
$after = memory_get_usage(FALSE);

/* clean up data */
unset($temp);

/* calculate the incresed memory usage */
$memory_usage = $after - $before;