$data=array
(
"Maths" : [
{
"Name" : "ramesh", // First element
"Marks" : 67,
"age" : 23
}, {
"Name" : "mayur", // Second element
"Marks" : 65,
"age" : 21
}
],
"Science" : [
{
"Name" : "ram", // First Element
"Marks" : 56,
"age" : 27
},
{
"Name" : "Santosh", // Second Element
"Marks" : 78,
"age" : 41
}
]
);
答案 0 :(得分:2)
您可以创建$data
并像这样编码json
<?php
$data = array
(
"Maths" => array(
array(
"Name" => "ramesh", // First element
"Marks" => 67,
"age" => 23
), array(
"Name" => "mayur", // Second element
"Marks" => 65,
"age" => 21
)
),
"Science" => array(
array(
"Name" => "ram", // First Element
"Marks" => 56,
"age" => 27
),
array(
"Name" => "Santosh", // Second Element
"Marks" => 78,
"age" => 41
)
)
);
echo json_encode($data);