php – 重复数组到一定长度?

我有一个数组,例如4个元素数组(“a”,“b”,“c”,d“);重复此数组以创建具有一定长度的新数组的最快方法是什么,例如71元素?
// the variables
$array = array("a","b","c","d");
$desiredLength = 71;
$newArray = array();
// create a new array with AT LEAST the desired number of elements by joining the array at the end of the new array
while(count($newArray) <= $desiredLength){
    $newArray = array_merge($newArray,$array);
}
// reduce the new array to the desired length (as there might be too many elements in the new array
$array = array_slice($newArray,$desiredLength);

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...