A
A
Alexey Nikolaev2018-03-19 05:12:39
PHP
Alexey Nikolaev, 2018-03-19 05:12:39

How to get value from array?

{
"setting": [{
   "item1": {
       "subitem": [1,"500"]
   },
   "item2": {
       "subitem": [3,"1000"]
   }
}]
}

You need to get the value, where 1000, from item2.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krypt3r, 2018-03-19
@krypt3r

<?php
$json =<<<JSON
{
"setting": [{
   "item1": {
       "subitem": [1,"500"]
   },
   "item2": {
       "subitem": [3,"1000"]
   }
}]
}
JSON;
$array = json_decode($json, true);
var_dump($array['setting'][0]['item2']['subitem'][1]);

string(4) "1000"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question