I have this JSON Object Array Type Data that I want to insert into array with keys. If I do print_r, the data seen as follows :
[{"comment":"hola hi ","datecreated":"2017-02-27 13:53:25"},{"comment":"hola hi harambeh ","datecreated" :"2017-02-27 13:53:30"}]
Here's my related code :
$data = json_decode($_REQUEST['array']);
$formdata = [];
foreach($data as $value){
$formdata = array('comment' => $value->comment, 'date_created' => $value->datecreated);
}
However, the result array only took the last object, which are
Array
(
[comment] => hola hi harambeh
[date_created] => 2017-02-27 13:53:30
)
Obviously I need every data, not just last one. This should be easy in JavaScript.
Any ideas and helps much appreciated.