j'ai un fichier json je voudrais gerer le champs null

$date = date("dmY");
$saut = "\n";

// chemin du fichier json programme
$json = file_get_contents("https://offline.turfinfo.api.pmu.fr/rest/client/7/programme/$date");
$data = json_decode($json,true);
$nb = count($data ['programme'] ['reunions']);
//$nc = count($data ['programme'] ['reunions']['courses']);
for($i = 0  ; $i < $nb ; $i ++){

$reunion         = $data ['programme'] ['reunions'][$i]['courses'] ;
//$nc              = $data ['programme'] ['reunions'][$i]['courses'][$i] ;

$reuni  = $i+1;
$course = $i+1;
var_dump($course);
echo 'R'.$reuni ;  
    foreach ($reunion as $r){

echo "<br>".$r ['cached'], " "
           .$r ['departImminent'], " "
           .$r ['timezoneOffset']," "
           .$r ['numReunion']
           .$r ['numOrdre']," "
           .$r ['numExterne']," "
           .$r ['heureDepart']," "
           .$r ['libelle'], " "
           .$r ['libelleCourt'], " "
           .$r ['montantPrix']," "
           .$r ['parcours']," "
           .$r ['distance']," "
           .$r ['distanceUnit']," "
           .$r ['corde']," "
           .$r ['discipline']," "
           .$r ['specialite']," "
           .$r ['categorieParticularite']," "
           .$r ['conditionSexe']," "
           .$r ['nombreDeclaresPartants']," "
           .$r ['grandPrixNationalTrot']," "
           .$r ['numSocieteMere']," "
           .$r ['pariMultiCourses']," "
           .$r ['pariSpecial']," "
           .$r ['montantTotalOffert']," "
           .$r ['montantOffert1er']," "
           .$r ['montantOffert2eme']," "
           .$r ['montantOffert3eme']," "
           .$r ['montantOffert4eme']," "
           .$r ['montantOffert5eme']," "
           // paris
           // fin paris
           .$r ['statut']," "
           .$r ['categorieStatut']," "
          // .$r ['participants']," "
          // .$r ['ecuries']," "
           .$r ['rapportsDefinitifsDisponibles']," "
           .$r ['isDepartImminent']," "
           .$r ['isDepartAJPlusUn']," "
           //.$r ['cagnottes']," "
          // .$r ['cagnottes']," "
           .$r ['replayDisponible']," "
           // hippodrome
           //.$r['code']," "
           //.$r['libelleCourt']," "
           //.$r['libelleLong']," "
           //fin hippodrome
           .$r ['epcPourTousParis']," "
           .$r ['courseTrackee']," "
           .$r ['courseExclusiveInternet']," "
           .$r ['formuleChampLibreIndisponible']," "
           .$r ['hasEParis'];
           //date Programme
           //.$r [''];
echo  "<br>". $saut;
    }
     }ourez votre code en utilisant "```" pour bien le mettre en forme. (ne copier pas trop de code)

Ce que je veux
je voudrai gerer les champs vide pour evidtez les erreur
et je voudrai rajouter une variable pour chaque course pour les reunion sa marche mais ma pour les course
je voudrais obtenir R1C1
j'ai essayer avec un (isset(.$r ['corde'])," " mais sa ne fonctionne pas
merci d'avance

Ce que j'obtiens
Notice: Undefined index: corde in C:\laragon\www\Pmu\reunion.php on line 41

1 réponse


Salut, vu que tu postes dans le forum Laravel, je pense que tu l'utilises, tu peux faire data_get($r, 'corde') et pareil pour tous les autres champ. Ca va essayer de récupérer l'index corde si il existe, sinon, ça retournera null.

Sinon, en php vanilla, tu peux faire $r['corde'] ?? null, sinon corde n'existe pas, alors ça retourne null.