if (empty($match_result['winners']) && empty($match_result['losers'])) { return false; } else { return true; } }); print_r($match_results); /** * Winners and losers have been determined. Perform major procedures here. * There are lots of queries being performed here; the script execution time may be 30s+. */ foreach ($match_results as $match_result) { $player_profile = new \BarracksMaster\PlayerProfile(); $num_players_total = sizeof($match_result['winners']) + sizeof($match_result['losers']); foreach ($match_result['winners'] as $payload_steamid) { if (!$player_profile->getByPayloadSteamId($payload_steamid)) { echo "\nCreating new profile for player: {$payload_steamid}\n"; $player_profile->create(['payload_steamid' => $payload_steamid]); } $player_profile->addMatch($match_result['match_id'], 'win', $num_players_total); } foreach ($match_result['losers'] as $payload_steamid) { if (!$player_profile->getByPayloadSteamId($payload_steamid)) { echo "\nCreating new profile for player: {$payload_steamid}\n"; $player_profile->create(['payload_steamid' => $payload_steamid]); } $player_profile->addMatch($match_result['match_id'], 'loss', $num_players_total); } } return 'complete'; });