Fill the array before issuing in JSON format as follows:

$json_data = array('from_login'=>$rows[$j]['from_login'], 'message_enc_from_key'=>$rows[$j]['message_enc_from_key'], 'who_login'=>$rows[$j]['who_login'], 'message_enc_who_key'=>$rows[$j]['message_enc_who_key'], 'date_time'=>$rows[$j]['date_time'] ); echo json_encode($json_data); 

There was a question how to fill this array with the array_push method. Tried like this:

 array_push($json_data, 'from_login'=>$rows[$j]['from_login']); 

But it gives an error of 500. What have I missed and am doing wrong?

    1 answer 1

    The array_push() function is not intended to fill in associative arrays; as a result of its operation, only index arrays are obtained. If you want to add a new element to an associative array, it’s better to do so.

     $json_data['from_login'] = $rows[$j]['from_login'];