Home Loop while changing the name of a variable
Reply: 0

Loop while changing the name of a variable

user1093
1#
user1093 Published in June 23, 2018, 8:02 am

Using FaceBook PHP SDK, when I want to get the next page of results I call something along the likes of $next = $fb->next($response). Now for the next page, I would have to call $next2 = $fb->next($next). I want to put this into a loop as obviously, I will never know beforehand how many times to execute this until I get through all the pages of results. When there are no more pages, the $fb->next() call will = null.

Here is an example without a loop:

$reactions = array();
$response = $response->getGraphEdge();

foreach ($response as $reaction) {
    $reactions[] = $reaction['name'] . " - " . $reaction['type'];
}

$next = $fb->next($response);
foreach ($next as $reaction) {
    $reactions[] = $reaction['name'] . " - " . $reaction['type'];
}

$next2 = $fb->next($next);
foreach ($next2 as $reaction) {
    $reactions[] = $reaction['name'] . " - " . $reaction['type'];
}

$next3 = $fb->next($next2);
foreach ($next2 as $reaction) {
    $reactions[] = $reaction['name'] . " - " . $reaction['type'];
}

print_r($reactions);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301973 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO