Hacking to Win Hacking to Win - 2 months ago 28
PHP Question

How to repeat foreach

This is the code:

$dat = getContents($id, $session);
foreach($dat['data']['followings'] as $gg){
$fid = $gg['fid'];
$f = follow($fid, $session, $atok);
echo $f['data']['credits'] . "\n";
}


When I'm run this script will get the result on my coin

Ex:

11
12

So, how to repeat the code until I get 50 coin or 100 or something like that?

Because on php just give me 2 result. I can make it to 10 or 50 or 100 but I just can with COPY PASTE these script. You know?

This is how I'm repeat this code:

$dat = getContents($id, $session);
foreach($dat['data']['followings'] as $gg){
$fid = $gg['fid'];
$f = follow($fid, $session, $atok);
echo $f['data']['credits'] . "\n";
}

$dat = getContents($id, $session);
foreach($dat['data']['followings'] as $gg){
$fid = $gg['fid'];
$f = follow($fid, $session, $atok);
echo $f['data']['credits'] . "\n";
}

$dat = getContents($id, $session);
foreach($dat['data']['followings'] as $gg){
$fid = $gg['fid'];
$f = follow($fid, $session, $atok);
echo $f['data']['credits'] . "\n";
}


So i can get 6 result. My questions is how to make the code without copy paste this code.

Answer
for($i = 0; $i < 10; $i++){
    $dat = getContents($id, $session);
    foreach ($dat['data']['followings'] as $gg){
        $fid = $gg['fid'];
        $f = follow($fid, $session, $atok);
        echo $f['data']['credits'] . "\n";
    }
}