I am getting two JSON arrays that I need merged each time a while loop runs a fetch from my database. This is the structure array result I am getting as of now:
{id=1,cid=1,fname=Lorna,vorname=King,gender=female,dob=1985,company=helsana,monthly_amount=150},
{id=2,cid=1,fname=Brian,vorname=King,gender=male,dob=2007,company=helsana,monthly_amount=100}
I need it to look like this:
{ 1={id:1, cid:1 fname=Lorna, vorname:King, gender:female, dob:1985, company:helsana, monthly_amount:100}, 2={id:2, cid:1 fname=Brian, vorname:King, gender:male, dob:2005, company:helsana, monthly_amount:150} }
To make it easier to pick values from the array. Here is the PHP code that I am using:
<?php
include_once "conn.php";
$show= $mysqli->query("SELECT id,cid,fname,vorname,gender,dob,company,monthly_amount FROM family where cid = '1' ");
$arr = array();
while($row = $show->fetch_assoc()){
$arr[] = $row;
}
$json_response = json_encode($arr, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
echo $str = substr($json_response, 1,-1);
?>
Am kinda new to this please someone help me out.