help pls, compare more variable (id) in other array!

Hi all, I have another question… and I don’t know how I can fix…

I get the first array as $resultsAchievementsMe, like this:

[php]$requestAchievementsMe = (new \Facebook\FacebookRequest( $session, ‘GET’, ‘/me/achievements?fields=data&app_id_filter=7606995873455’))->execute()->getGraphObject(\Facebook\GraphUser::className());

$resultsAchievementsMe = $requestAchievementsMe ->asArray();
$tests = $resultsAchievementsMe[‘data’];

print_r($tests);[/php]

the print_r, will write this:

[php]Array ( [0] => stdClass Object ( [data] => stdClass Object ( [importance] => 0 [achievement] => stdClass Object ( [id] => 6467916820996 [url] => https://www.***.com/test2.html [type] => game.achievement [title] => TITLE2!! ) ) [id] => 10206139019499208 ) )[/php]

this array, would contain more than 1 achievement, the user will unlock more than one…

now, with this:

[php]if (empty($resultsAchievementsMe)) {
echo ‘no achievements unlocked for now’;
}else {
foreach ($resultsAchievementsMe[‘data’] as $tests) {
$totalAchievementsMe .= ‘[["’ . $tests->data->achievement->id .’"],["’. $tests->data->achievement->title.’"]],’;
}
}[/php]

the output wuold be (id of the achievment unlocked by the user)(name of it), and would contain more information, I means, more achievement, because if the user unlock a new one, when he restart the app, this array will have another one with the same method (id),(name achievement)

[php][[“6467916820996”],[“TEST2!!”]],[/php]

Now, this another array, has all of the achievment, and I get with the similar method:

[php]$requestAchievements = (new \Facebook\FacebookRequest( $session, ‘GET’, ‘/7606995873455/achievements’))->execute()->getGraphObject(\Facebook\GraphUser::className());

$resultsAchievements = $requestAchievements ->asArray();

print_r($resultsAchievements);[/php]

the output of print_r, would be like this:

[php]Array ( [0] => stdClass Object ( [url] => https://www.***.com/test2.html [type] => game.achievement [title] => TITLE2!! [image] => Array ( [0] => stdClass Object ( [url] => https://www.***.com/test2.png [width] => 198 [height] => 198 ) ) [description] => description achievement2 [updated_time] => 2015-02-22T14:51:54+0000 [data] => stdClass Object ( [points] => 100 ) [id] => 6467916820996 [application] => stdClass Object ( [id] => 7606995873455 [name] => myapp [url] => https://apps.facebook.com/myapp/ ) [context] => stdClass Object ( [display_order] => 0 ) ) [1] => stdClass Object ( [url] => https://www.***.com/test1.html [type] => game.achievement [title] => TEST1!! [image] => Array ( [0] => stdClass Object ( [url] => https://www.***.com/test1.png [width] => 198 [height] => 198 ) ) [description] => description achievement1 [updated_time] => 2015-02-22T14:51:46+0000 [data] => stdClass Object ( [points] => 50 ) [id] => 7829964917383 [application] => stdClass Object ( [id] => 7606995873455 [name] => EatSquare [url] => https://apps.facebook.com/myapp/ ) [context] => stdClass Object ( [display_order] => 0 ) ) )[/php]

This array, has more information, like the description of the achievment, the url of the picture…etc… but with the similar method as before:

[php]$expic = “png”;
foreach ($resultsAchievements as $result) {

$totalAchievements .= ‘[["’ . $result->data->points .’"],["’. $UNLOCKED? .’"],["’. $result->title .’"],["’. $result->description .’"],["’. $result->id .’"],["’. $result->url = substr($result->url, 0, -4).$expic.’"]],’;
}[/php]

It will get this:

[php][[“100”],[“TEST2!!”],[“VARIABLE I NEED TO MAKE**”],[“description achievement2”],[“6467916820996”],[“https://www.*.com/test2.png"]],[[“50”],[“TEST1!!”],["VARIABLE I NEED TO MAKE”],[“description achievement1”],[“7829964917383”],[“https://www.***.com/test1.png”]],[/php]

now, you can see, the user has the test2 id (6467916820996) unlocked from the first array… but I would like to make just one array, and insert a new value in the second one to see the all ID for each achievement unlocked…so, the final output will be like:

[php][[“100”],[“TEST2!!”],[“UNLOCKED**”],[“description achievement2”],[“6467916820996”],[“https://www.*.com/test2.png"]],[[“50”],[“TEST1!!”],["LOCKED!!!”],[“description achievement1”],[“7829964917383”],[“https://www.***.com/test1.png”]],[/php]

I try this, but doesn’t works…

[php]$testid=$result->id;
$exist=false;

foreach($resultsAchievementsMe['data'] as $resultsAchievements){
   if($testid ==  $result->id) {  
      $totalAchievements .= $result->data->points .'"],["'. $result->title .'"],["'. 'UNLOCKED' .'"],["'. $result->description .'"],["'. $result->id .'"],["'.  $result->url .'"],';
      $exist=true;
      break;
  }

}
if ($exist == false) {
$totalAchievements .=$result->data->points .’"],["’. $result->title .’"],["’. ‘LOCKED!!!’ .’"],["’. $result->description .’"],["’. $result->id .’"],["’. $result->url.’"],["’;
}[/php]

someone has some idea? I need to compare for every achievement of $resultsAchievements if in the other array exist the achievement (of the user, the first one), the example, would be like the last output…

thank you very much, I search a lot, but I didn’t find anything… ???

thanks

nobody can help me to make a function?

Maybe I know how can works, If I make a function loop that compare the (first* a variable who start with zero ) id of the achivement user, with all of the other achievement (in the other array) with a loop, and when the loop is = of the height of the other array, add +1 to the first* variable and restart the process for all of the achievement user, and when the achievement user are finished, just print the other achievement locked…

can works? I have difficult to make this kind of process… but I’m right? ???

Sponsor our Newsletter | Privacy Policy | Terms of Service