Answers for "php get specific key value from json to array"

PHP
2

read key value json php

// json object.
    $contents = '{"firstName":"John", "lastName":"Doe"}';

    // Option 1: through the use of an array.
    $jsonArray = json_decode($contents,true);

    $key = "firstName";

    $firstName = $jsonArray[$key];


    // Option 2: through the use of an object.
    $jsonObj = json_decode($contents);

    $firstName = $jsonObj->$key;
Posted by: Guest on January-12-2021
0

php get json objects by key without indez

foreach($arr as $i => $json) {
    $arr[$i] = json_decode($json, true);
}
Posted by: Guest on October-02-2021

Code answers related to "php get specific key value from json to array"

Browse Popular Code Answers by Language