📅  最后修改于: 2022-03-11 14:53:55.025000             🧑  作者: Mango
// 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;