I need to output only the values ​​from the array. But it contains values ​​and arrays. How can I do it?

Array:

Array ( [query] => Array ( [ids] => Array ( [0] => 35080600 ) [dimensions] => Array ( [0] => ym:s:date ) [metrics] => Array ( [0] => ym:s:goal33151467users [1] => ym:s:users ) [sort] => Array ( [0] => ym:s:date ) [date1] => 2017-09-05 [date2] => 2019-02-22 [limit] => 50 [offset] => 1 [goal_id] => 33151467 [group] => day [auto_group_size] => 1 [quantile] => 50 [offline_window] => 21 [attribution] => Last [currency] => RUB ) [data] => Array ( [0] => Array ( [dimensions] => Array ( [0] => Array ( [name] => 2017-09-05 ) ) [metrics] => Array ( [0] => 1 [1] => 220 ) ) [1] => Array ( [dimensions] => Array ( [0] => Array ( [name] => 2017-09-06 ) ) [metrics] => Array ( [0] => 3 [1] => 218 ) ) [2] => Array ( [dimensions] => Array ( [0] => Array ( [name] => 2017-09-07 ) ) [metrics] => Array ( [0] => 4 [1] => 206 ) ) ) 

Code:

 foreach ($Data['data'] as $key) { foreach ($key as $r) { echo '<pre>'; echo $r[0]; } } 

Result:

 Array - не должно быть 1 Array - не должно быть 3 Array - не должно быть 4 
  • one
    There is_array - u_mulder Feb. 2:58 pm
  • It is necessary to display numbers, that is - ['data'] [0] ['metrics'] [0]. But he perceives the last 0 as an array. There should be only numbers - 1, 3, 4 - Vitaly Kessel
  • Oh, I understand you. - Vitaly Kessel
  • Poor looking into the documentation of php. - Vitaly Kessel
  • What's wrong with $key['metrics'][0] ? - u_mulder

1 answer 1

It's not very clear what your difficulties are. All subarrays in 'data' have the same structure, therefore:

 foreach ($Data['data'] as $item) { echo $item['metrics'][0] . '<br '>'; }