3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); ini_set('display_errors', 1); function run(){ $apiKey = 'demo'; $clanMembers = json_decode(getData('http://api.worldoftanks.com/wgn/clans/info/?application_id='.$apiKey.'&fields=members.account_name%2Cmembers.account_id&clan_id=1000021200'),true); $data = array(); $players = array(); foreach ($clanMembers['data']['1000021200']['members'] as $key) { $urls[] = 'http://api.worldoftanks.com/wot/globalmap/eventaccountinfo/?application_id='.$apiKey.'&fields=events.battles%2Cevents.battles_to_award%2Cevents.fame_points%2Cevents.rank&event_id=black_gold_first_step&front_id=1511_us_c4event1_front_1&account_id='.$key['account_id']; $players[] = array($key['account_name'],$key['account_id']); } $urls = array_chunk($urls, 20,true); for($i = 0;$i<5;$i++){ $data = array_merge($data,multiRequest($urls[$i])); } $data2 = array(); foreach ($data as $key => $value) { //echo $key; $data2[$players[$key][1]] = json_decode($value,true)['data'][$players[$key][1]]['events']['black_gold_first_step']; $data2[$players[$key][1]][0]['account_name'] = $players[$key][0]; $data2[$players[$key][1]][0]['account_id'] = $players[$key][1]; } print_r($data2); return $data2; } function getData($url){ $rCURL = curl_init(); curl_setopt($rCURL, CURLOPT_URL, $url); curl_setopt($rCURL, CURLOPT_HEADER, 0); curl_setopt($rCURL, CURLOPT_RETURNTRANSFER, 1); $aData = curl_exec($rCURL); curl_close($rCURL); return $aData; } function multiRequest($data, $options = array()) { // array of curl handles $curly = array(); // data to be returned $result = array(); // multi handle $mh = curl_multi_init(); // loop through $data and create curl handles // then add them to the multi-handle foreach ($data as $id => $d) { $curly[$id] = curl_init(); $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d; curl_setopt($curly[$id], CURLOPT_URL, $url); curl_setopt($curly[$id], CURLOPT_HEADER, 0); curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1); // post? if (is_array($d)) { if (!empty($d['post'])) { curl_setopt($curly[$id], CURLOPT_POST, 1); curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']); } } // extra options? if (!empty($options)) { curl_setopt_array($curly[$id], $options); } curl_multi_add_handle($mh, $curly[$id]); } // execute the handles $running = null; do { curl_multi_exec($mh, $running); } while($running > 0); // get content and remove handles foreach($curly as $id => $c) { $result[$id] = curl_multi_getcontent($c); curl_multi_remove_handle($mh, $c); } // all done curl_multi_close($mh); return $result; } ?> <html> <head> <title>Fame Points -MO-</title> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css"> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.min.css"/> <script type="text/javascript" src="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.min.js"></script> </head> <body> <table id="example" class="display" cellspacing="0"> <thead> <tr> <th>Player</th> <th>Battles</th> <th>Rank</th> <th>Fame Points</th> <th>Battles Needed</th> </tr> </thead> <tbody> <?php $data = run(); //print_r($data); foreach ($data as $value) { if($value[0]['battles']>0){ echo "<tr> <td>".$value[0]['account_name']."</td> <td>".$value[0]['battles']."</td> <td>".$value[0]['rank']."</td> <td>".$value[0]['fame_points']."</td> <td>".$value[0]['battles_to_award']."</td> </tr>"; } } ?> </tbody> </table> <script type="text/javascript"> $(document).ready(function() { $('#example').DataTable(); } ); </script> </body> </html>
Output for 7.0.0 - 7.2.8
<html> <head> <title>Fame Points -MO-</title> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css"> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.min.css"/> <script type="text/javascript" src="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.min.js"></script> </head> <body> <table id="example" class="display" cellspacing="0"> <thead> <tr> <th>Player</th> <th>Battles</th> <th>Rank</th> <th>Fame Points</th> <th>Battles Needed</th> </tr> </thead> <tbody> Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/djbtm:37 Stack trace: #0 /in/djbtm(9): getData('http://api.worl...') #1 /in/djbtm(144): run() #2 {main} thrown in /in/djbtm on line 37
Process exited with code 255.
Output for 5.4.11 - 5.6.28
<html> <head> <title>Fame Points -MO-</title> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css"> <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.min.css"/> <script type="text/javascript" src="https://cdn.datatables.net/s/dt/dt-1.10.10/datatables.min.js"></script> </head> <body> <table id="example" class="display" cellspacing="0"> <thead> <tr> <th>Player</th> <th>Battles</th> <th>Rank</th> <th>Fame Points</th> <th>Battles Needed</th> </tr> </thead> <tbody> Fatal error: Call to undefined function curl_init() in /in/djbtm on line 37
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/djbtm on line 25
Process exited with code 255.