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..