0

I have an array containing a lot of records. I need to split it into 4 smaller arrays. How can I do this?

0

3 Answers 3

3

Use the array_chunk function: http://php.net/manual/en/function.array-chunk.php

$numberOfSmallerArrays = 4;
$arrayOfSmallerArrays = array_chunk($largeArray, ceil(count($largeArray) / $numberOfSmallerArrays));
Sign up to request clarification or add additional context in comments.

1 Comment

...then do the truffle shuffle.
0

Try array_chunk.

Comments

0

Find a criteria, and to something like:

$vCurrentArr = array(1, 2, 3, 4,4);

$vArray1 = array(); 
$vArray2 = array(); 
$vArray3 = array(); 
$vArray4 = array(); 


foreach($arr as &$value) {
 if($value=1) {
    $vArray1[count($vArray1)+1]=$value;
  } else if($value=2) {
    $vArray2[count($vArray2)+1]=$value;
  } else if($value=3) {
    $vArray3[count($vArray3)+1]=$value;
  } else if($value=4) {
    $vArray4[count($vArray4)+1]=$value;
  }
}

Comments

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.