duanmo6937 2017-06-28 02:34
浏览 18

使用api请求循环遍历chunked数组

I have a function which gets data with an API request. I sending an array (called) $result with that request. This array contains metadata of the actual data I am posting.

The problem is:

The array is too big to handle for the api request.

string(186) " invalid input too much data to parse out into domains "

So I thought of splitting up the array with this function:

echo ("<pre>");
print_r (smallify($result, 15));
echo ("<pre/>");

function smallify($arr, $numberOfSlices){
    $sliceLength = sizeof($arr) / $numberOfSlices;
    for($i=1; $i<=$numberOfSlices; $i++){
        $arr1 = array_chunk($arr, $sliceLength*$i);
        return $arr1;
        unset($arr1);
    }
}

And it works pretty well.

Now, how do I access the internal array indexes and assign them a variable so that I can loop through the api request for each chunk?

Here's the API request:

// The last parameter of the Domain is the the array.
// I want to make a request for every chunked array.

$domains = file_get_contents("http://www.somedomain.com/api.php?username:Pw:getinfo=$result");
var_dump($domains);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失