I was making a short little program to split a long integer into smaller bits. At the moment, what it does is simply put one digit of the int orderly into an index of $arr.
$grip = 10001; $fade = '';
for ($i = 1; $i <= trim($grip); $i++) {
$par = rand(0, 9); $fade .= "$par"; }
$arr = chunk_split($fade, 451, "
");
echo $arr[1]; sleep(10);
I'm really hoping chunk_split does what I think it does and splits a string/int by a certain length.... Any help is thankfully accepted. :D
chunk_split()
doesn't return an array, but rather a string. If you want to use it, you would have to convert the string returned by chunk_split()
into an array:
$arr = explode("
", chunk_split($fade, 451, "
"));
If you want an efficient solution though, you might want to consider something like:
$grip = 10001;
$fade = '';
$arr = array();
for ($i = 1; $i <= $grip; $i++) {
$fade .= rand(0, 9);
if ($i % 451 == 0) {
$arr[] = $fade;
$fade = '';
}
}
if (!empty($fade)) {
$arr[] = $fade;
}