Разобрать php массив

111
16 сентября 2021, 08:20

Ребят подскажите пожалуйста как разобрать многомерный массив с помощью php

array(3) {
  ["status"]=>
  int(1)
  ["stats"]=>
  array(1) {
    [0]=>
    array(8) {
      ["slice"]=>
      array(3) {
        ["day"]=>
        int(16)
        ["month"]=>
        int(10)
        ["year"]=>
        int(2019)
      }
      ["traffic"]=>
      array(2) {
        ["raw"]=>
        string(1) "4"
        ["uniq"]=>
        string(1) "4"
      }
      ["actions"]=>
      array(6) {
        ["total"]=>
        array(5) {
          ["charge"]=>
          int(25)
          ["earning"]=>
          int(5)
          ["null"]=>
          int(2)
          ["revenue"]=>
          int(20)
          ["count"]=>
          int(3)
        }
        ["confirmed"]=>
        array(5) {
          ["charge"]=>
          int(0)
          ["earning"]=>
          int(0)
          ["null"]=>
          int(2)
          ["revenue"]=>
          int(0)
          ["count"]=>
          int(2)
        }
        ["pending"]=>
        array(5) {
          ["charge"]=>
          int(25)
          ["earning"]=>
          int(5)
          ["null"]=>
          int(0)
          ["revenue"]=>
          int(20)
          ["count"]=>
          int(1)
        }
        ["declined"]=>
        array(5) {
          ["charge"]=>
          int(0)
          ["earning"]=>
          int(0)
          ["null"]=>
          int(0)
          ["revenue"]=>
          int(0)
          ["count"]=>
          int(0)
        }
        ["not_found"]=>
        array(5) {
          ["charge"]=>
          int(0)
          ["earning"]=>
          int(0)
          ["null"]=>
          int(0)
          ["revenue"]=>
          int(0)
          ["count"]=>
          int(0)
        }
        ["hold"]=>
        array(5) {
          ["charge"]=>
          int(0)
          ["earning"]=>
          int(0)
          ["null"]=>
          int(0)
          ["revenue"]=>
          int(0)
          ["count"]=>
          int(0)
        }
      }
      ["views"]=>
      int(0)
      ["ctr"]=>
      int(0)
      ["cr"]=>
      array(6) {
        ["total"]=>
        int(75)
        ["confirmed"]=>
        int(50)
        ["pending"]=>
        int(25)
        ["declined"]=>
        int(0)
        ["not_found"]=>
        int(0)
        ["hold"]=>
        int(0)
      }
      ["ratio"]=>
      string(3) "1:1"
      ["epc"]=>
      int(0)
    }
  }
  ["pagination"]=>
  array(4) {
    ["per_page"]=>
    int(1)
    ["total_count"]=>
    int(7)
    ["page"]=>
    int(1)
    ["next_page"]=>
    int(2)
  }
}
Answer 1

Если вам нужно только эти два значения, почему бы не перебрать массив stats и просто вывести нужные значение, многомерность тут ни причем

Допустим как то так

foreach($youArray['stats'] as $stat) {
    echo 'Value "raw" - ' . $stat['traffic']['raw'];
    echo 'Value "uniq" - ' . $stat['traffic']['uniq'];
}
Answer 2
$data=array("status"=>"1", "stats"=>array("0"=>array("slice"=>array("day"=>"16", "month"=>"10", "year"=>"2019"),
                                               "traffic"=>array("raw"=>"4","uniq"=>"4"),
                                               "actions"=>array("total"=>array("charge"=>"25","earning"=>"5","null"=>"2","revenue"=>"20","count"=>"3"),
                                                                "confirmed"=>array("charge"=>"0","earning"=>"0","null"=>"2","revenue"=>"0","count"=>"2"),
                                                                "pending"=>array("charge"=>"25", "earning"=>"5","null"=>"0","revenue"=>"20","count"=>"1"),
                                                                "declined"=>array("charge"=>"0", "earning"=>"0","null"=>"0","revenue"=>"0","count"=>"0"),
                                                                "not_found"=>array("charge"=>"0","earning"=>"0","null"=>"0","revenue"=>"0","count"=>"0"),
                                                                "hold"=>array("charge"=>"0","earning"=>"0","null"=>"0","revenue"=>"0","count"=>"0")
                                                                ),
                                               "views"=>"0",
                                               "ctr"=>"0",
                                               "cr"=>array("total"=>"75","confirmed"=>"50","pending"=>"25","declined"=>"0","not_found"=>"0","hold"=>"0"),
                                               "ratio"=>"1:1","epc"=>"0")),
                                               "pagination"=>array("per_page"=>"1","total_count"=>"7","page"=>"1","next_page"=>"2")
);

print_r($data["stats"][0]["traffic"]["uniq"]);
READ ALSO
Как получить Instagram access_token в правильном формате?

Как получить Instagram access_token в правильном формате?

После авторизации в Instagram я получаю access_token но проблема в том что я получаю его в следующем формате:

231
Массив дат из CarbonPeriod

Массив дат из CarbonPeriod

всем привет, подскажите пожалуйста как в моем случае получить массив c датами с 2018-06-14 по 2018-06-20?

99
Вывести строки массива json по отдельности

Вывести строки массива json по отдельности

Есть Json массив, $json = json_decode($content, true); выводится он в таком виде:

170
Как получить из многомерного массива два значения в массив? Laravel

Как получить из многомерного массива два значения в массив? Laravel

Всем привет, подскажите пожалуйста, как получить из многомерного массива два значения в массив? чтобы потом можно было к каждому из них обращаться...

266