I have to add new elements to a sub array
I used the code to set values in a single depth array but now i have to add values to sub array
foreach($result["data"] as $val)
{
$qry = "SELECT count(tin) as tincnt , count(tout) as toutcnt FROM inout
WHERE NAME = '".$val["NAME"]."'";
$prs = oci_parse($conn,$qry);
$exec = oci_execute($prs);
oci_define_by_name($prs,"tincnt",$tin);
oci_define_by_name($prs,"toutcnt",$tout);
if(!$exec)
{
$result['STATUS']="error";
$result['MESSAGE']="errcd 3 : error fetching data";
}
else
{
oci_fetch($prs);
$val->{'TOTAL_IN'} = $tin;
$val->{'TOTAL_OUT'} = $tout;
}
}
$val->{'TOTAL_IN'} = $tin; // gives error Attempt to assign property of non-object
Input
{
"data": [
{
"NAME1": "Sukhwinder",
"PHONE1": "9516152737",
"ADDRESS": "Jalandhar"
},
{
"NAME1": "Sapna",
"PHONE1": "8787878787",
"ADDRESS": "Jalandhar"
}
],
"STATUS": "SUCCESS",
"CNT": "2",
"HASDATA": true
}
desired output
{
"data": [
{
"NAME1": "Sukhwinder",
"PHONE1": "9516152737",
"ADDRESS": "Jalandhar",
"TOTAL_IN":5
"TOTAL_OUT":4
},
{
"NAME1": "Sapna",
"PHONE1": "8787878787",
"ADDRESS": "Jalandhar",
"TOTAL_IN":4
"TOTAL_OUT":4
}
],
"STATUS": "SUCCESS",
"CNT": "2",
"HASDATA": true
}