I just started learning about JSON. I have to create a static multidimensional array which later required to convert to json encode. Now I get confused in creating multiple array. The below are the code that I have tried. I should have many post and author in this array. But it is printing only single post and author. I am not sure where I exactly did mistake.
<?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'
);
$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 = array($data);
$rss = (object) array('data'=>$datas);
$json = json_encode($rss);
echo $json;
$datadeclarations will be overwriting previous declarations because you are reusing the same keys. ...your$dataarray will only have two subarrays: 'post' (once) and 'author' (once).[], but let's see what you are doing to get here.