开发者

How can i divide this array to chunks?

开发者 https://www.devze.com 2023-03-29 16:04 出处:网络
I want to divide array into specific chunks Like array1 = 24%; 开发者_JS百科array2 = 50%; array3 = 26%;

I want to divide array into specific chunks

Like

array1 = 24%;
 开发者_JS百科    array2 = 50%;
     array3 = 26%;

$myArray = array("abc","def","ghi","jkl","mno","pqr","stu","vwx","yz");
$newArray = array_chunk($myArray, 3, false);

Array may contain billions of records.


$cnt=count($myArray);
$cnt1=round($cnt*0.24);
$cnt2=round($cnt*0.5);

//use array_slice $here

array(
    array_slice($array,0,$cnt1);
    array_slice($array,$cnt1,$cnt2);
    array_slice($array,$cnt1+$cnt2);
);


Try looking into array_slice().

0

精彩评论

暂无评论...
验证码 换一张
取 消