![]() |
PHP looping with step of 100
Hello everyone. I'm trying to get all the information from the people my user follows on twitter. The problem is with twitter you have to make 2 separate calls to get all the information:
Call 1 returns all the ID's of the users my user follows. Call 2 returns the user information of up to 100 users which can be asked via a comma separated argument. So basically I have to get all the user ids from first call and then run 100 at a time through call 2 and put them in another array for storage. I've been digging at this for a while and haven't been able to come up with a solution. I figured array_splicing might be the way to go but I haven't been able to increment it correctly. This is what I've been able to do so far... Code:
$users_array = array(); |
Is this object member actually an array:
$tw_user_array->ids? Array_splice is probably not what you want. That has the purpose of extracting a part of an array, and then inserting a chunk into it. Doesn't mean it won't work, but it looks to me that you probably want to use array_slice instead which is to remove a part of an array. PHP Code:
This block is unnecessary: PHP Code:
PHP Code:
Don't know anything about these objects you are using, but they may have a built in pagination functionality as well. Also, if you are looping and breaking into chunks of 100 (you don't have anything here that shows this, but it is described as such), simply use array_chunk. PHP Code:
|
Wow. That was super helpful. I wasn't familiar with the array_chunk function. Really helpful. This is the code that ended up working for me.
Code:
$users_array = array(); |
| All times are GMT +1. The time now is 08:56 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.