John Davidson

php - Access value of object from json_decode

0 comments
Message:


I'm trying to access at value of key->value,

this is my var_dump of $data = json_decode($_POST['data']);


array(8) {
[0]=> object(stdClass) {
["key"]=> string(7) "address"
["value"]=> string(16) "via le mani dal "
}
[1]=> object(stdClass) {
["key"]=> string(21) "tempistica_in_vendita"
["value"]=> string(18) "Tra più di 3 mesi"
}
}

how can I access to "Tra più di 3 mesi" asking the value of tempistica_in_vendita ?



My Answer:
To access the value of a key from an object decoded using `json_decode`, you can simply use the arrow operator `->` to access the key's value. Here's an example:

php
$json = '{"key": "value"}';
$obj = json_decode($json);

echo $obj->key; // Output: value


In this example, we first decode the JSON string into an object using `json_decode`. Then, we access the value of the key "key" using the arrow operator `->`.

Rate this post

5 of 5 based on 5648 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us