<?php
$a = [
"name",
"age"
];
var_dump( json_encode($a));
the result is"["name", "age"]"
this is a json data is fine, but what is returned is a json collection and what I need is a json object, I expect the following result
"{"name", "age"}",
my solution now is to change my code as follows
$a = [
"name" => 1,
"age" => 1
];
var_dump( json_encode($a));
that is, to change the array into a key-value pair, each key has the same value of 1, which is useless. The result is as follows:
"{"name": 1, "age": 1}"
this can meet my needs, but personally, this is a bit too low. I don"t know if there is a good way