我只想显示此数组参数“ firstPerson”的json_encode。
$someArray = [
"firstPerson" => [
"name" => "Jonathan",
"gender" => "male"
],
"secondPerson" => [
"name" => "William",
"gender" => "male"
],
"thirdPerson" => [
"name" => "Allison",
"gender" => "female"
]
];
// Convert Array to JSON String
$someJSON = json_encode($someArray);
echo $someJSON;
答案 0 :(得分:0)
您可以获取第一个元素,然后将其编码为json:
$someJSON = json_encode($someArray['firstPerson']);
echo $someJSON;
// output :
// {"name":"Jonathan","gender":"male"}