PHP는 json 다중 배열을 만듭니다. PHP와 코드를 다음과 같은 출력을 필요로 그 json .. 너무 많은 배열과 개체 나를 혼란. 우리가 사용 wordpresPHP는 json 다중 배열을 만듭니다
<?php
$categories = get_categories(array(
'orderby' => 'name',
'parent' => 0
));
foreach ($categories as $category) {
$category_id = $category->term_id;
$category_name = $category->name;
echo $category_name;
echo "<br>";
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category' => $category_id
);
$myposts = get_posts($args);
foreach($myposts as $post){
$category_postname = $post->post_title;
echo $category_postname;
echo "<br>";
}
}
?>
빌 출력은
Testcat1
pos1
post2
Testcat2
post3
post4
TestCat3
post5
post 6
는이 같은 JSON을 만들 필요가있다 "이다. 내가이 JSON 출력처럼 필요
{
"data": [
{
"cat": "Testcat1",
"post": [
{
"name": "post1"
},
{
"name": "post2"
}
]
},
{
"cat": "Testcat2",
"post": [
{
"name": "post3"
},
{
"name": "post4"
}
]
},
{
"cat": "Testcat3",
"post": [
{
"name": "post5"
},
{
"name": "post6"
}
]
}
]
}
을
이
json_encode는 어떻습니까? – Jeff