doudou8893 2013-01-30 01:05
浏览 232
已采纳

致命错误:允许的内存大小为134217728字节耗尽(尝试分配36个字节)

i have made a function will return N-th digit of sequence number, example :

1234567891011121314151617

  • The 5-th digit is 5
  • The 20-th digit is 1

My function is like this

 <?php
   function getLength($number) {
   $length = 0;
   if ($number == 0){
      $length = 1;
   } else {
      $length = (int) log10($number)+1;
   }
     return $length;
  }
 ?>

<?php
 function getDigitNumber($digit){
   $number = 10000000000;
   $data = array();
   for($i=1;$i<=$number;$i++){  
   if(getLength($i) > 1){
     $array = str_split($i,1);
    for($n=0;$n<=count($array)-1;$n++){
        array_push($data,$array[$n]);
    }   
}else{
    $data[$i] = $i;
}
  } 
return $data[$digit];
}
?>

When i executed that i've a problem like this error message "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes)". Maybe because i assign a large number in var $number

How can i fix that..or how can i make function that can handle these large number

thanks..

  • 写回答

2条回答 默认 最新

  • duancan1950 2013-01-30 01:08
    关注

    i have made a function will return N-th digit of sequence number, example :

    1234567891011121314151617

    The 5-th digit is 5
    The 20-th digit is 1
    

    Why not:

    $number[5];
    $number[20];
    

    The number has to be a string anyways, so just access the character with array syntax.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探