I have hard time creating the following JSON format using PHP code below. Please suggest.
PHP Code
$postArray = array(
"MainPage" => array(
"i_date"=> "10-10-2012",
"i_location"=>$_POST["location-text"],
"i_summary"=>$_POST["summary-text"],
"SubPage" => "[" array(
"first_name"=> $_POST["first-1"],
"last_name"=>$_POST["last-1"]
),
array(
"first_name"=>$_POST["first-2"],
"last_name"=>$_POST["last-2"]
) "]"
)
);
array_push($postArray["MainPage"]["SubPage"],
array(
"first_name"=>$_POST["first-3"],
"last_name"=>$_POST["last-3"]
)
);
$json = json_encode( $postArray );
Here is the final ouput I am trying to achieve.
{
"MainPage":{
"i_date":"2014-03-20",
"i_location":"test",
"i_summary":"test test",
"SubPage":[
{
"first_name":"first name test1",
"last_name":"last name test1"
},
{
"first_name":"first name test2",
"last_name":"last name test2"
},
{
"first_name":"first name test3",
"last_name":"last name test3"
}
]
}
}