我刚开始学习JSON。我必须创建一个静态多维数组,后来需要转换为json编码。现在我对创建多个数组感到困惑。以下是我尝试过的代码。我应该在这个数组中有很多帖子和作者。但它只打印单个帖子和作者。我不确定我错在哪里。
develop
答案 0 :(得分:1)
试试这个,你可以查看live demo
<?php
$data['post']= array(
'title' => 'This is title',
'message' =>'This is message',
'datetime' => 'This is date time',
'bannerImage' =>''
);
$data['author']= array(
'authorName' => 'Jason Bourne',
'userType' => 'Registered User',
'address' => 'New York',
'profilePic' => 'Profile picture'
);
$datas[] = $data;
$data['post']= array(
'title' => 'This is title1',
'message' =>'This is message1',
'datetime' => 'This is date time1',
'bannerImage' =>''
);
$data['author']= array(
'authorName' => 'Jason Bourne1',
'userType' => 'Registered User1',
'address' => 'New York1',
'profilePic' => 'Profile picture1'
);
$datas[] = $data;
$json = json_encode(array('data'=>$datas));
echo $json;