I'm working on a website utilizing an Xbox API that returns gameplayed information for a given user. It returns results in the json format:
{
"Data": {
"Gamertag": "Major Nelson",
"Gamerpic": "https:\/\/avatar-ssl.xboxlive.com\/avatar\/Major%20Nelson\/avatarpic-l.png",
"GameCount": 779,
"TotalEarnedGamerScore": 63147,
"TotalPossibleGamerScore": 593465,
"TotalEarnedAchievements": 3429,
"TotalPossibleAchievements": 25498,
"TotalPercentCompleted": 13,
"PlayedGames": [
{
"Id": 1297287449,
"Title": "Halo 4",
"Url": "http:\/\/marketplace.xbox.com\/en-US\/Title\/1297287449",
"BoxArt": "https:\/\/www.xboxleaders.com\/img\/boxart\/1297287449-small.jpg",
"LargeBoxArt": "https:\/\/www.xboxleaders.com\/img\/boxart\/1297287449-large.jpg",
"EarnedGamerScore": 705,
"PossibleGamerScore": 1500,
"EarnedAchievements": 38,
"PossibleAchievements": 67,
"PercentageCompleted": 56.7,
"LastPlayed": 1363751187
},
]
},
"Stat": "ok",
"In": 3.818,
"Authed": "false",
"AuthedAs": null
}
I'm trying to create an array that will check the info of two different users so I can create a for loop to display only the game Titles and BoxArt both users have played (regardless of percentage complete or other variables). I've tried the following code:
<?php
$gamertag = isset($_GET['tag']) ? $_GET['tag'] : null;
$friendtag = isset($_GET['ftag']) ? $_GET['ftag'] : null;
$gamertag2 = urlencode($gamertag);
$friendtag2 = urlencode ($friendtag);
// Get game information
$games = json_decode(url_get_contents('http://www.xboxleaders.com/api/games.json?gamertag='.$gamertag2));
$games = $games->Data;
$fgames = json_decode(url_get_contents('http://www.xboxleaders.com/api/games.json?gamertag='.$friendtag2));
$fgames = $fgames->Data;
?>
<?php
$array1 = array($games->PlayedGames->Title);
$array2 = array($fgames->PlayedGames->Title);
$result = array_intersect($array1, $array2);
print_r($result);
?>
But this always returns an empty set. When I just use $games->PlayedGames for the arrays, it merges the two array and displays all the data in each. I would really appreciate a means to compare two users array that will give me just the Titles and Boxart of the games two users have in common.