D
D
darkwhiteman2017-01-30 19:17:09
PHP
darkwhiteman, 2017-01-30 19:17:09

How to output string from json inside json in php?

Get a response from the server like this:

{"message":
  [{"id":52957,"title":"название","description":"","subevents":
    [{"id":542032,"date":"2017-02-05T10:00:00"}]
  }]
  [{"id":52917,"title":"название","description":"","subevents":
     [{"id":542032,"date":"2017-02-05T10:00:00"}]
  }]
}

I output like this:
$json = json_decode($result, true);
foreach ($json['message'] as $ob) {
echo "<div id='".$ob['id']."' class=\"item\"><img src=\"/templates/scoopit.jpg\" alt=\"...\">
            <h4>".$ob['title']."</h4>
                <small>".$ob['subevents']['date']."</small>
                <p><a href=\"#\" class=\"btn btn-default\" role=\"button\">Подробнее</a></p>
    </div>";

But the date is not displayed. Tried various ways, but it doesn't work. Maybe someone knows

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-01-30
@darkwhiteman

subevents is an array.
$ob['subevents'][0]['date']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question