0

how can i split a Dabble fetch all query into separate arrays? I'd divide, for ex, 1 million records into 10 arrays and make the same operation for every array.. I've this problem because i've tofind a way to not overload php memory buffer..

Many thanks, steve

1 Answer 1

0

You can use array_chunk to do that. Basically give the database fetch result to the function.

You can check this link: http://php.net/manual/tr/function.array-chunk.php

EDIT

for($x=0; $x<30; $x++)
    $mainArray[]="Data X";

$split=array_chunk($mainArray,3);

echo "<pre>";
print_r($split);
echo "</pre>";

RESULT

Array
(
[0] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[1] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[2] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[3] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[4] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[5] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[6] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[7] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[8] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

[9] => Array
    (
        [0] => Data X
        [1] => Data X
        [2] => Data X
    )

)
Sign up to request clarification or add additional context in comments.

10 Comments

I know, but with chunk fn i'll split one array into N arrays. I need a fn that every X records (for ex. 100000) create a chunk...
You can split the main array into smaller arrays by every X recors, for example if the $mainArray has 20 rows, you can split it 5 by 5 with array_chunk($mainArray,5);
:@ And how can i obtain the numbers of generated arrays?
$newArrays=array_chunk($mainArray,5); and $numberOfNewArrays=count($newArrays);
p.s. array_chunk($mainArray,5); doesn't split every 5 records but split in 5 arrays....this isn't what i'm searching...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.