Read 209 times | Created 2013-03-13 07:09:26 | Updated 2013-03-20 09:28:41 | | |

 

<?php
$n=10000000000000;
$t1 = MICROTIME(TRUE);
function get_digit($n){
  $i=1;
  $a=0;
  while($n>9*pow(10,$i-1)*$i)
  {
    $n-=pow(10,$i-1)*9*$i;
    $a+=pow(10,$i-1)*9;
    $i++;
  }
  $x=($a+ceil($n/$i));
  return array(substr($x,($n-1)%$i,1),$i,$x,$n,$a);
}
$m1=memory_get_usage();
$h=get_digit($n);
$m2=memory_get_usage();
echo "Ambil karakter pada posisi: $n <br>";
echo "BatasDigit: ".$h[1]." <br />";
echo "Berada pada angka: ".$h[2]." <br />";
echo "Yaitu angka: ".$h[0] ."<br />";
$t2 = MICROTIME(TRUE);
echo "Makan waktu: ".($t2 - $t1)." sekon<br />";
echo "Makan memory: ".($m2 - $m1)." bytes<br />";