PHP arrays
$grades = array( array( name => "tom",
grade => 'A'
),
array( name => "jeff",
grade=> 'B'
),
array( name => "lisa",
grade => 'C'
)
);
$output=array
( 'status'=>'ok',
'content'=>$grades
)
And the final JSON output I want to see would be {"status":'ok',"content":"{"tom":"A","jeff":"B","lisa":"B"}"}
The question is how should I manipulated the array so it can give me the final output like above JSON?
would json_encode($output); echo $output do the trick?
or
Do I have to do
json_encode($grades) then another json_encodes($output) but I am seeing extra \ thing like {"status":1,"content":"{\"tom\":\"A\",\"jeff\":\"B\",\"lisa\":\"B\"}"}
I don’t understand why you don’t write just this:
It prints:
Isn’t is the expected result?