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

时间:2012-06-27 17:37:21

标签: php

  

可能重复:
  Is there a way I get the size of a PHP variable in bytes?

我需要使用php为int / char或数组找到大小(以字节为单位)。我认为它可以通过php进行内存管理。

1 个答案:

答案 0 :(得分:0)

/* 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;