V
V
Vladislav Radzimovsky2014-10-30 12:45:01
PHP
Vladislav Radzimovsky, 2014-10-30 12:45:01

How to take neighbor object in object(stdClass) when parsing JSON?

Hello! There was a small problem when parsing json:
After passing json through json_decode, I get a couple of thousand objects like this:

object(stdClass)#1103 (3) {
    ["name"]=>
    string(7) "TTSfs13"
    ["type"]=>
    array(4) {
      [0]=>
      object(stdClass)#1104 (3) {
        ["availability"]=>
        string(11) "unavailable"
        ["warehouse"]=>
        string(3) "231"
      }
      [1]=>
      object(stdClass)#1105 (3) {
        ["availability"]=>
        string(11) "unavailable"
        ["warehouse"]=>
        string(3) "443"
      }
    }
  }

How can you specify only 'name' to get the values ​​of neighboring 'type' without going through everything in a loop?
Let's say all this json_decode is in the $arr variable;
And need to get $arr->product->type knowing $arr->product->name
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2014-10-30
@Lafafm

IMHO, it's easier to run the source data once in a loop and form your own array with the necessary keys and parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question