user3518291
user3518291

Reputation: 171

Json. Get value by others known value (PHP)

i have this json object

"ok": {
"ok1" : 3,
"ok2" : 4
}

I will try to get ok2 by ok1..

This is my current function, but its not working.

echo ["ok"]["ok1"][3]->["ok2"];

But it doesnt print out anything

Please help! Thanks

Upvotes: 0

Views: 36

Answers (1)

ek9
ek9

Reputation: 3442

You CANNOT get OK2 by OK1, because OK2 does not belong to OK1. The structure of your JSON is that OK1 and OK2 both belong to OK.

So only this will work:

// ok1
var_dump(["ok"]["ok1"]);
// ok2
var_dump(["ok"]["ok2"]);

Also you seem to include the value (["ok"]["ok1"][3]) which is NOT going to work. Only use the keys (["ok"]["ok1"]).

Upvotes: 1

Related Questions