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

Loop while changing the name of a variable

user4393
1#
user4393 Published in September 20, 2018, 12:44 pm

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);
share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO