M
M
MrZed2021-07-01 19:02:54
PHP
MrZed, 2021-07-01 19:02:54

How to read json value?

Hey! There is a .json file:

{
  "posts" : [
    {
      "id" : 0,
      "title" : "Авто 1",
      "description" : "Описание",
      "active" : true
    },
      
    {
      "id" : 1,
      "title" : "Авто 2", 
      "description" : "Описание",
      "active" : true
    }
  ]
}

How to read the value of "title" in this element:
{
  "id" : 1,
  "title" : "Авто 2",
  "description" : "Описание",
  "active" : true
}

What would be the output Авто 2
I wrote the code:
$json = file_get_contents('file.json');
$json_read= json_decode($json, true);

$json_read['posts'][0]['id']['value']

And I get:
{ "posts" : [ { "id" : 0, "title" : "Авто 1", "description" : "Описание", "active" : true }, { "id" : 1, "title" : "Авто 2", "description" : "Описание", "active" : true } ] }

And I don't know what's next.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-07-01
@MrZed

$json_read['posts'][1]['title'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question