Api array php

Résolu
bonjour,
avec une api d'un jeux,avec une url je peux récupérer des informations sur un joueurs du jeux.avec cette url je voudrais recuperer les array,comment faire ?

exemple : url = "blabla.com" ;

[{"playerId":51037035,"championId":12,"championLevel":5,"championPoints":58890,"lastPlayTime":1466737091000,"championPointsSinceLastLevel":37290,"championPointsUntilNextLevel":0,"chestGranted":true,"tokensEarned":0},

echo $array[1] ;

merci

1 réponse

  1. Modérateur
    Bonjour
    ce que récupères semble être du json.
    donc un json_decode devrait suffire
    1. oui :/

      $homep = '';

      $arr = json_decode($homep, true);

      foreach ($arr as $k=>$v){
      echo $v;
      }
      sa m'affiche :
      0 : Array
      1 : Array
      2 : Array
      3 : Array
      4 : Array
      5 : Array
      6 : Array
      7 : Array
      8 : Array
      9 : Array
    2. Modérateur
      Fais donc un
      print_r ($arr);
    3. en faite avec ce json :
      [{"playerId":51037035,"championId":12,"championLevel":5,"championPoints":58890,"lastPlayTime":1466737091000,"championPointsSinceLastLevel":37290,"championPointsUntilNextLevel":0,"chestGranted":true,"tokensEarned":0},{"playerId":51037035,"championId":21,"championLevel":5,"championPoints":44974,"lastPlayTime":1459357838000,"championPointsSinceLastLevel":23374,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":236,"championLevel":5,"championPoints":42983,"lastPlayTime":1465661615000,"championPointsSinceLastLevel":21383,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":89,"championLevel":5,"championPoints":41534,"lastPlayTime":1463855929000,"championPointsSinceLastLevel":19934,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":429,"championLevel":5,"championPoints":40801,"lastPlayTime":1465988670000,"championPointsSinceLastLevel":19201,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":222,"championLevel":5,"championPoints":37471,"lastPlayTime":1465270736000,"championPointsSinceLastLevel":15871,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":104,"championLevel":5,"championPoints":34852,"lastPlayTime":1462895569000,"championPointsSinceLastLevel":13252,"championPointsUntilNextLevel":0,"chestGranted":true,"tokensEarned":0},{"playerId":51037035,"championId":67,"championLevel":5,"championPoints":28673,"lastPlayTime":1467318064000,"championPointsSinceLastLevel":7073,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":9,"championLevel":5,"championPoints":28153,"lastPlayTime":1455197642000,"championPointsSinceLastLevel":6553,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0},{"playerId":51037035,"championId":133,"championLevel":5,"championPoints":24081,"lastPlayTime":1453493846000,"championPointsSinceLastLevel":2481,"championPointsUntilNextLevel":0,"chestGranted":false,"tokensEarned":0}]

      j'aimerai recuperer tous les championid avec pour chaque championid ,le championpoint
    4. Contributeur
      @lightdevDans ce cas...
      $arr = json_decode($homep, true);
      foreach ($arr as $c){
          echo $c['championId'] . " " . $c['championPoints'] . "<br>\n";
      }
    5. grand merci :)