0

I have the following and I'm trying to get the numbers after 'items' (2034, 6390, 9803) and their values.

array (
  'items' => 
  array (
    2034 => 
    array (
      0 => 
      array (
        'type' => 31,
        'id' => -1901750,
        'time' => '52:31',
      ),
    ),
    6390 => 
    array (
      0 => 
      array (
        'desc' => 'Box',
        'type' => 1,
        'id' => 1901750,
        'time' => '52:31',
      ),
    ),
    9803 => 
    array (
      0 => 
      array (
        'type' => 30,
        'id' => -1901809,
        'time' => '84:27',
      ),
    ),
  ),
)

I've tried the following and returns an error Notice: Array to string conversion

$decode_two = json_decode($str2,TRUE);

foreach($decode_two['items'] as $value2) {

    echo '<li>' . $value2 . ' </li>';
}

I know what the error means but I'm not sure what to put after $value2[?].

Thank you

trunks
  • 147
  • 2
  • 9

2 Answers2

2

You can loop with key and val as :

foreach($decode_two['items'] as $key => $val) {
  echo '<li>' . $key . ' </li>';
}
Kawaljeet Singh
  • 357
  • 1
  • 5
0
$decode_keys = array_keys($decode_two['items']);
bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72