Avatar billede ulrich Novice
24. maj 2018 - 11:47 Der er 2 kommentarer og
2 løsninger

Hjælp med arrays

Hej,

Jeg har brug for hjælp til at hive data ud af dette array:

array(3) {
  ["data"]=>
  array(5) {
    ["type"]=>
    string(6) "player"
    ["id"]=>
    string(40) ""
    ["attributes"]=>
    array(7) {
      ["stats"]=>
      NULL
      ["titleId"]=>
      string(13) ""
      ["shardId"]=>
      string(5) "pc-eu"
      ["createdAt"]=>
      string(20) "2018-04-07T10:09:23Z"
      ["updatedAt"]=>
      string(20) "2018-04-07T10:09:23Z"
      ["patchVersion"]=>
      string(0) ""
      ["name"]=>
      string(8) ""
    }
    ["relationships"]=>
    array(2) {
      ["assets"]=>
      array(1) {
        ["data"]=>
        array(0) {
        }
      }
      ["matches"]=>
      array(1) {
        ["data"]=>
        array(10) {
          [0]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "e2f74a07-6388-4aef-9122-1680511a2410"
          }
          [1]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "ad66a387-ee34-41ac-8cd8-8faa2ccd93e5"
          }
          [2]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "b14bb5c3-b4cd-430c-a493-b2b7aee01af3"
          }
          [3]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "b8b94b2f-d5de-433b-a3f1-315b6dc88b56"
          }
          [4]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "8fccb4de-7ba9-49ff-86d6-3dc6f5e0169b"
          }
          [5]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "9d222078-22f4-403b-ab57-2caba2951452"
          }
          [6]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "9f36c0d8-6e23-4698-8e02-f1f47b7cdff9"
          }
          [7]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "fdb2aed8-d5a5-40e5-876c-d23cbbb0a8dd"
          }
          [8]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "e6177e64-e356-4b8c-82fa-815d370f1ac1"
          }
          [9]=>
          array(2) {
            ["type"]=>
            string(5) "match"
            ["id"]=>
            string(36) "ea77648d-d069-4cc4-8fb6-2bfd2659d26b"
          }
        }
      }
    }
    ["links"]=>
    array(2) {
      ["self"]=>
      string(95) "https://api.playbattlegrounds.com/shards/pc-eu/players/"
      ["schema"]=>
      string(0) ""
    }
  }
  ["links"]=>
  array(1) {
    ["self"]=>
    string(95) "https://api.playbattlegrounds.com/shards/pc-eu/players/"
  }
  ["meta"]=>
  array(0) {
  }
}

Hvordan gennemløber jeg matches? For fx at få matchid ud.
Avatar billede Slettet bruger
24. maj 2018 - 14:15 #1
Avatar billede michael_stim Ekspert
24. maj 2018 - 14:40 #2
#1
Nu er spörgsmålet oprettet i PHP-kategorien, så mon ikke det skal väre PHP.

https://www.w3schools.com/php/php_arrays.asp
https://www.w3schools.com/php/php_arrays_multi.asp
Avatar billede olsensweb.dk Ekspert
24. maj 2018 - 18:12 #3
>Hvordan gennemløber jeg matches? For fx at få matchid ud.
ca sådan, hvor $ar er det array du har posted

<?php
$liste = $ar["data"]["relationships"]["matches"]["data"];
for ($i = 0, $lng = count($liste); $i < $lng; $i++) {
    echo $liste[$i]['id'] . ", ";
}
?>
Avatar billede ulrich Novice
24. maj 2018 - 20:36 #4
Takker =)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester