I need to get an JSON structure as following:
{
"emails": [
{
"sender": "shihas#abc.com",
"unread_count": 2,
"items": [
{
"id": "89",
"email": "shihas#abc.com",
"read": "0",
},
{
"id": "32",
"email": "shihas#abc.com",
"read": "0",
}
]
},
{
"sender": "marias123#gmail.com",
"unread_count": 0,
"items": [
{
"id": "2",
"email": "marias123#gmail.com",
"read": "1",
}
]
},
{
"sender": "gutar4320#hotmail.com",
"unread_count": 1,
"items": [
{
"id": "1",
"email": "gutar4320#hotmail.com",
"read": "0",
}
]
}
]
}
Array($hire_email):
In the below array I need to group all the details based on the email. And also count the no. of unread messages(i.e read = 0).
Array
(
[0] => Array
(
[id] => 89
[email] => shihas#abc.com
[read] => 0
)
[1] => Array
(
[id] => 32
[email] => shihas#abc.com
[read] => 0
)
[2] => Array
(
[id] => 2
[email] => marias123#gmail.com
[read] => 1
)
[3] => Array
(
[id] => 1
[email] => gutar4320#hotmail.com
[read] => 0
)
)
The following is the code snippet used for maintaining the JSON structure.
foreach($hire_email as $val) {
if($val['read']==0){ $count++; }else{ $count = 0;}
$hire_group_email[$val['email']]['sender'] = $val['email'];
$hire_group_email[$val['email']]['unread_count'] = $count;
$hire_group_email[$val['email']]['items'][] = $val;
}
$output["emails"][] = $hire_group_email;
echo json_encode($output);
This should do the trick.
$hire_email =array(
array(
"id" => "89",
"email" => "shihas#abc.com",
"read" => "0"
),
array
(
"id" => "32",
"email" => "shihas#abc.com",
"read" => "0"
),
array
(
"id" => "2",
"email" => "marias123#gmail.com",
"read" => "1"
),
array
(
"id" => "1",
"email" => "gutar4320#hotmail.com",
"read" => "0"
)
);
$tmp = array();
foreach($hire_email as $arg)
{
$tmp[$arg['email']][] = $arg;
}
$output = array();
foreach($tmp as $type => $labels)
{
$count = 0;
foreach ($labels as $value) {
if($value['read']==0){ $count++; }else{ $count = 0;}
}
$output[] = array(
'sender' => $type,
'unread_count' => $count,
'items' => $labels
);
}
echo json_encode($output);
Try doing it like this, using: array_sum and array_column, the rest is just picking out the first items values.
$array = json_decode($json, true)['emails'];
$result = [];
foreach($array as $val) {
$result[] = [
'id' => $val['items'][0]['id'],
'email' => $val['items'][0]['email'],
'read' => array_sum(array_column($val['items'], 'read'))
];
}
$output["emails"] = $result;
echo json_encode($output, JSON_PRETTY_PRINT);
Result:
{
"emails": [
{
"id": "89",
"email": "shihas#abc.com",
"read": 0
},
{
"id": "2",
"email": "marias123#gmail.com",
"read": 1
},
{
"id": "1",
"email": "gutar4320#hotmail.com",
"read": 0
}
]
}
https://3v4l.org/hi7qm
And if you want it as shown ;p (my mistake, misread it):
Loop over each item, then loop over the items and use that to build the output.
$array = json_decode($json, true)['emails'];
$result = [];
foreach($array as $val) {
foreach ($val['items'] as $item) {
$result[] = [
'id' => $item['id'],
'email' => $item['email'],
'read' => array_sum(array_column($val['items'], 'read'))
];
}
}
$output["emails"] = $result;
echo json_encode($output, JSON_PRETTY_PRINT);
Result:
{
"emails": [
{
"id": "89",
"email": "shihas#abc.com",
"read": 0
},
{
"id": "32",
"email": "shihas#abc.com",
"read": 0
},
{
"id": "2",
"email": "marias123#gmail.com",
"read": 1
},
{
"id": "1",
"email": "gutar4320#hotmail.com",
"read": 0
}
]
}
https://3v4l.org/eU95A
Related
I need to create a json with this format:
{
"reservs": [
{
"ResId": "58",
"time": "2020-05-15 19:41:50",
"boxEntering": null,
"boxClosing": null,
"active": "1",
"UserId": "29",
"BoxId": "4",
"boxPlace": null,
"box": {
"id": "4",
"Nom": "Hortillonages",
"Lat": "49.8953",
"Lng": "2.31034",
"place": "0",
"placeMax": "9"
}
}
]
}
in entries, a $header who check the user token(not use for my problem)
$table the table returned from PDO::FETCHASSOC from sql SELECT request
My php code:
function generateJson($table, headerChecker $header){
$final = array();
foreach ($table as $item) {
$box = array(
"id" => $item["id"],
"Nom" => $item["Nom"],
"Lat" => $item["Lat"],
"Lng" => $item["Lng"],
"place" => $item["place"],
"placeMax" => $item["placeMax"]
);
$reserv = array(
"ResId" => $item["ResId"],
"time" => $item["time"],
"boxEntering" => $item["boxEntering"],
"boxClosing" => $item["boxClosing"],
"active" => $item["active"],
"UserId" => $item["UserId"],
"BoxId" => $item["BoxId"],
"boxPlace" => $item["boxPlace"],
);
$reserv["box"] = $box;
array_merge($final,$reserv);
}
$arr = array("reservs" => $table);
$header->tokenJson($arr);
echo json_encode($arr);
}
I have this result
{"reservs": [
{
"ResId": "58",
"time": "2020-05-15 19:41:50",
"boxEntering": null,
"boxClosing": null,
"active": "1",
"UserId": "29",
"BoxId": "4",
"boxPlace": null,
"id": "4",
"Nom": "Hortillonages",
"Lat": "49.8953",
"Lng": "2.31034",
"place": "0",
"placeMax": "9",
"QRID": "",
"boxToken": ""
}]
}
I think the Json format eror is in the array_merge function.
What add array function can I use to not remove the Box object
Your problem is that you are not assigning the return of array_merge and using the wrong variable $table. Just dynamically append to $final:
foreach ($table as $item) {
// this all appears good
//
$reserv["box"] = $box;
$final[] = $reserv; // append to $final
}
$arr = array("reservs" => $final); // use $final
$header->tokenJson($arr);
echo json_encode($arr);
Merge the new $reserv into $final and assign it to $final, then use $final.
Try this one
function generateJson($table, headerChecker $header){
$final = array();
foreach ($table as $item) {
$box = array(
"id" => $item["id"],
"Nom" => $item["Nom"],
"Lat" => $item["Lat"],
"Lng" => $item["Lng"],
"place" => $item["place"],
"placeMax" => $item["placeMax"]
);
$reserv = array(
"ResId" => $item["ResId"],
"time" => $item["time"],
"boxEntering" => $item["boxEntering"],
"boxClosing" => $item["boxClosing"],
"active" => $item["active"],
"UserId" => $item["UserId"],
"BoxId" => $item["BoxId"],
"boxPlace" => $item["boxPlace"],
);
$reserv["box"] = $box;
$final[] = $reserv;
}
$arr = array("reservs" => $final);
$header->tokenJson($arr);
echo json_encode($arr);
}
I just learned php
I have a separate database table, and I want to combine that table with only 1 parameter with JSON output, but the resulting output is wrong, how to change my JSON to json which is correct and easy to use.
thanks
json output :
[
[
{
"id_service": "3",
"reference_number": "",
"tracking_number": "RJC-0000-0001",
"kd_inbound": "INB-1000-0001",
"tgl_inbound": "2019-11-07 00:00:00",
"status_inb": "1"
}
],
[
{
"id_service": "3",
"reference_number": "",
"kd_outbag": "BAG-1468-0002",
"tanggal_outbag": "2019-11-07 00:00:00",
"status_outbag": "1"
}
],
[
{
"id_service": "3",
"reference_number": "",
"kd_outbound": "OTB-1826-0001",
"tgl_outbound": "2019-11-07 17:04:49",
"status_otb": "1"
}
],
]
this my code
public function awb_get() {
$id = $this->get('tracking_number');
$res= array(
$this->M_tarif->tampil_status_inbound($id),
$this->M_tarif->tampil_status_otboundbag($id),
$this->M_tarif->tampil_status_otboundori($id),
$this->M_tarif->tampil_status_indes($id),
$this->M_tarif->tampil_status_outdes($id),
$this->M_tarif->tampil_status_runsheet($id),
$this->M_tarif->tampil_db_service_status($id)
);
$this->response($res, 200);
}
i want in like this
{
"status": 200,
"error": false,
"awb": [
{
"tracking_number": "RJC-0000-0004",
"status": "order",
"tanggal": "2019-10-30"
},
{
"tracking_number": "RJC-0000-0004",
"status": "Inbound to origin",
"tanggal": "2019-11-03"
}
]
}
Your json response is not correct.
So, first you have to reset your JSON before send to function. I was make sample to rearrange JSON and convert it in stdClass Object. Please check below code to convert with your response.
$arr ='[
[
{
"id_service": "3",
"reference_number": "",
"tracking_number": "RJC-0000-0001",
"kd_inbound": "INB-1000-0001",
"tgl_inbound": "2019-11-07 00:00:00",
"status_inb": "1"
}
],
[
{
"id_service": "3",
"reference_number": "",
"kd_outbag": "BAG-1468-0002",
"tanggal_outbag": "2019-11-07 00:00:00",
"status_outbag": "1"
}
],
[
{
"id_service": "3",
"reference_number": "",
"kd_outbound": "OTB-1826-0001",
"tgl_outbound": "2019-11-07 17:04:49",
"status_otb": "1"
}
],
]';
$result = str_replace(array('[',']','\n'), '',htmlspecialchars(json_encode($arr), ENT_NOQUOTES));
$str = preg_replace('/\\\"/',"\"", $result);
$json = '[';
$json .= substr($str, 2,-1); // Substring -1 character from the end of the json variable, this will be the trailing comma.
$json .= ']';
$jsonData = preg_replace("/,(?!.*,)/", "", $json);
echo "<pre>";
print_r(json_decode($jsonData));
echo "</pre>";
output:
Array
(
[0] => stdClass Object
(
[id_service] => 3
[reference_number] =>
[tracking_number] => RJC-0000-0001
[kd_inbound] => INB-1000-0001
[tgl_inbound] => 2019-11-07 00:00:00
[status_inb] => 1
)
[1] => stdClass Object
(
[id_service] => 3
[reference_number] =>
[kd_outbag] => BAG-1468-0002
[tanggal_outbag] => 2019-11-07 00:00:00
[status_outbag] => 1
)
[2] => stdClass Object
(
[id_service] => 3
[reference_number] =>
[kd_outbound] => OTB-1826-0001
[tgl_outbound] => 2019-11-07 17:04:49
[status_otb] => 1
)
)
This is what the result i need to come out with
"data": [
{
"ticket_category_id": "677",
"ticket_category_name": " Testing 500",
"ticket_category_order": "1",
"tickets":
[
{
"ticket_id": "927",
"ticket_title": "EDI Project Template with attachments",
"ticket_order": "1",
"due_date": "0000-00-00 00:00:00",
"created_date": "2018-05-16 10:01:04",
"edited_date": "2018-05-17 02:56:38",
"updated_date": "2018-05-17 02:56:38",
"is_complete": "0",
"total_comment": "0",
"total_attachment": "10",
"total_checklist_items": "48",
"total_completed_checklist_items": "0",
"label": [
{
"ticket_label_name": "",
"ticket_color_code": "#FF3B30"
},
"#D4891C": {
"ticket_label_name": "IN PROGRESS",
"ticket_color_code": "#D4891C"
}]
},
"people": []
},
{
"ticket_id": "928",
"ticket_title": "EDI Project Template",
"ticket_order": "2",
"due_date": "0000-00-00 00:00:00",
"created_date": "2018-05-16 10:01:04",
"edited_date": "0000-00-00 00:00:00",
"updated_date": "0000-00-00 00:00:00",
"is_complete": "0",
"total_comment": "0",
"total_attachment": "0",
"total_checklist_items": "48",
"total_completed_checklist_items": "0",
"label": [
{
"ticket_label_name": "",
"ticket_color_code": "#4CD964"
}]
},
"people": []
}
]
But what i get the result is like below
{
"data": [
{
"ticket_category_id": "677",
"ticket_category_name": " Testing 500",
"ticket_category_order": "1",
"tickets": {
"927": {
"ticket_id": "927",
"ticket_title": "EDI Project Template with attachments",
"ticket_order": "1",
"due_date": "0000-00-00 00:00:00",
"created_date": "2018-05-16 10:01:04",
"edited_date": "2018-05-17 02:56:38",
"updated_date": "2018-05-17 02:56:38",
"is_complete": "0",
"total_comment": "0",
"total_attachment": "10",
"total_checklist_items": "48",
"total_completed_checklist_items": "0",
"label": {
"#FF3B30": {
"ticket_label_name": "",
"ticket_color_code": "#FF3B30"
}
},
"people": []
}
}
},
{
"ticket_category_id": "677",
"ticket_category_name": " Testing 500",
"ticket_category_order": "1",
"tickets": {
"927": {
"ticket_id": "927",
"ticket_title": "EDI Project Template with attachments",
"ticket_order": "1",
"due_date": "0000-00-00 00:00:00",
"created_date": "2018-05-16 10:01:04",
"edited_date": "2018-05-17 02:56:38",
"updated_date": "2018-05-17 02:56:38",
"is_complete": "0",
"total_comment": "0",
"total_attachment": "10",
"total_checklist_items": "48",
"total_completed_checklist_items": "0",
"label": {
"#D4891C": {
"ticket_label_name": "IN PROGRESS",
"ticket_color_code": "#D4891C"
}
},
"people": []
}
}
},
And below is the code I have done, I using php mysql one to many relationship get all the data to be flat array, and then below code is convert single flat array into three multidimension array, but i meet a bottleneck. Please help to review my code to point out which part I need to change to become my expected result.
$result = array();
foreach($total_count as $Key => $Value){
$ticketCatId = $Value['ticket_category_id'];
$ticketId = $Value['ticket_id'];
$ticketColorCode = $Value['ticket_color_code'];
$ticketMember = $Value['user_id'];
$result[$ticketCatId]['ticket_category_id'] = $Value['ticket_category_id'];
$result[$ticketCatId]['ticket_category_name'] = $Value['ticket_category_name'];
$result[$ticketCatId]['ticket_category_order'] = $Value['ticket_category_order'];
if(!isset($result[$ticketCatId]['tickets'])) {
$result[$ticketCatId]['tickets'] = array();
}
// this code is append the ticket ID
if($ticketId && !isset($result[$ticketCatId]['tickets'][$ticketId])) {
$ticket = array(
'ticket_id' => $Value['ticket_id'],
'ticket_title' => $Value['ticket_title'],
'ticket_order' => $Value['ticket_order'],
'due_date' => $Value['due_date'],
'created_date' => $Value['created_date'],
'edited_date' => $Value['edited_date'],
'updated_date' => $Value['updated_date'],
'is_complete' => $Value['is_complete'],
'total_comment' => $Value['total_comment'],
'total_attachment' => $Value['total_attachment'],
'total_checklist_items' => $Value['total_checklist_items'],
'total_completed_checklist_items' => $Value['total_completed_checklist_items'],
'label' => array(),
'people' => array()
);
$result[$ticketCatId]['tickets'][$ticketId] = $ticket;
}
if($ticketColorCode && isset($result[$ticketCatId]['tickets'][$ticketId]) && !isset($result[$ticketCatId]['tickets'][$ticketId]['label'][$ticketColorCode])) {
$ticketColor = array(
'ticket_label_name' => $Value['ticket_label_name'],
'ticket_color_code' => $Value['ticket_color_code']
);
$result[$ticketCatId]['tickets'][$ticketId]['label'][$ticketColorCode] = $ticketColor;
}
if($ticketMember && isset($result[$ticketCatId]['tickets'][$ticketId]) && !isset($result[$ticketCatId]['tickets'][$ticketId]['people'][$ticketMember])) {
$ticketPeople = array(
'user_id' => $Value['user_id'],
'photo' => $Value['photo']
);
$result[$ticketCatId]['tickets'][$ticketId]['people'][$ticketMember] = $ticketPeople;
}
}
dd(json_encode(["data"=>$result]));
I don't have any sample data to work with, so I can't actually test this for you. The general idea though is that each time through the loop, you initialize a temporary array ($tmpArray = array();) and put all the loop-specific values into that array. Then, at the end of each loop iteration, you push that temporary array onto your $results array ($result[] = $tmpArray;), allowing PHP to automatically create sequential indexes for $results. The reason why you are getting nested JSON objects currently is because json_encode() will only produce JSON arrays from sequentially-index PHP arrays
$result = array();
foreach($total_count as $Key => $Value){
$ticketCatId = $Value['ticket_category_id'];
$ticketId = $Value['ticket_id'];
$ticketColorCode = $Value['ticket_color_code'];
$ticketMember = $Value['user_id'];
$tmpArray = array();
$tmpArray['ticket_category_id'] = $Value['ticket_category_id'];
$tmpArray['ticket_category_name'] = $Value['ticket_category_name'];
$tmpArray['ticket_category_order'] = $Value['ticket_category_order'];
if(!isset($tmpArray['tickets'])) {
$tmpArray['tickets'] = array();
}
// this code is append the ticket ID
if($ticketId && !isset($tmpArray['tickets'][$ticketId])) {
$ticket = array(
'ticket_id' => $Value['ticket_id'],
'ticket_title' => $Value['ticket_title'],
'ticket_order' => $Value['ticket_order'],
'due_date' => $Value['due_date'],
'created_date' => $Value['created_date'],
'edited_date' => $Value['edited_date'],
'updated_date' => $Value['updated_date'],
'is_complete' => $Value['is_complete'],
'total_comment' => $Value['total_comment'],
'total_attachment' => $Value['total_attachment'],
'total_checklist_items' => $Value['total_checklist_items'],
'total_completed_checklist_items' => $Value['total_completed_checklist_items'],
'label' => array(),
'people' => array()
);
$tmpArray['tickets'][$ticketId] = $ticket;
}
if($ticketColorCode && isset($tmpArray['tickets'][$ticketId]) && !isset($tmpArray['tickets'][$ticketId]['label'][$ticketColorCode])) {
$ticketColor = array(
'ticket_label_name' => $Value['ticket_label_name'],
'ticket_color_code' => $Value['ticket_color_code']
);
$tmpArray['tickets'][$ticketId]['label'][$ticketColorCode] = $ticketColor;
}
if($ticketMember && isset($tmpArray['tickets'][$ticketId]) && !isset($tmpArray['tickets'][$ticketId]['people'][$ticketMember])) {
$ticketPeople = array(
'user_id' => $Value['user_id'],
'photo' => $Value['photo']
);
$tmpArray['tickets'][$ticketId]['people'][$ticketMember] = $ticketPeople;
}
$result[] = $tmpArray;
}
dd(json_encode(["data"=>$result]));
I have an array like below:
Array ( [0] => Array ( [SI] => 1
[name] => Nick
[location] => Russia
[year] => 2011 )
[1] => Array ( [SI] => 8
[name] => Mike
[location] => Russia
[year] => 2011 )
[2] => Array ( [SI] => 2
[name] => Tom
[location] => Russia
[year] => 2010 )
[3] => Array ( [SI] => 6
[name] => Duke
[location] => Russia
[year] => 2010 ) )
Current JSON format:
{
"name": "Amalians",
"img": "https:\/\/dl.dropboxusercontent.com\/u\/19954023\/marvel_force_chart_img\/marvel.png",
"children": [
{
"name": "2011"
},
{
"children": [
{
"SI": "1"
}
]
},
{
"children": [
{
"name": "Nick"
}
]
},
{
"children": [
{
"location": "Russia"
}
]
},
{
"name": "2011"
},
{
"children": [
{
"SI": "8"
}
]
},
{
"children": [
{
"name": "Mike"
}
]
},
{
"children": [
{
"location": "Russia"
}
]
},
{
"name": "2010"
},
{
"children": [
{
"SI": "2"
}
]
},
{
"children": [
{
"name": "Tom"
}
]
},
{
"children": [
{
"location": "Russia"
}
]
},
{
"name": "2010"
},
{
"children": [
{
"SI": "6"
}
]
},
{
"children": [
{
"name": "Duke"
}
]
},
{
"children": [
{
"location": "Russia"
}
]
}
]
}
Desired JSON format:
{
"name": "marvel",
"img": "https://dl.dropboxusercontent.com/u/19954023/marvel_force_chart_img/marvel.png",
"children": [
{
"name": "2011",
"children": [
{
"SI": "1",
"name": "Nick",
"location": "Russia"
},
{
"SI": "8",
"name": "Mike",
"location": "Russia"
}
]
},
{
"name": "2010",
"children": [
{
"SI": "2",
"name": "Tom",
"location": "Russia"
},
{
"SI": "6",
"name": "Duke",
"location": "Russia"
}
]
}
]
}
CODE:
$data['name'] = "Amalians";
$data['img'] = "https://dl.dropboxusercontent.com/u/19954023/marvel_force_chart_img/marvel.png";
foreach($people as $row)
{
$data['children'][]['name'] = $row['year'];
$data['children'][]['children'][]['SI'] = $row['SI'];
$data['children'][]['children'][]['name'] = $row['name'];
$data['children'][]['children'][]['location'] = $row['location'];
}
echo "<pre>";
echo json_encode($data,JSON_PRETTY_PRINT);
echo "</pre>"; exit();
NOTE: $people is the array defined above.
Please kindly help me to do this. I have been working on this for last two days and till this moment I couldn't find any solution. Thanks
i guess the simplest way is to group your data
$arrData = [
[
"SI" => 1,
"name" => "Nick",
"location" => "Russia",
"year" => 2011
],
[
"SI" => 2,
"name" => "Mike",
"location" => "Russia",
"year" => 2011
],
[
"SI" => 3,
"name" => "Tom",
"location" => "Russia",
"year" => 2010
],
[
"SI" => 4,
"name" => "Duke",
"location" => "Russia",
"year" => 2010
],
];
$arrGroupedData = [];
foreach($arrData AS $row)
{
$arrGroupedData[$row['year']][] = [ "SI" => $row['SI'], "name" => $row['name'], "location" => $row['location']];
}
$arrGroupFormattedData = [];
foreach($arrGroupedData AS $key => $arrGroup)
{
$arrGroupFormattedData[] = ["name" => $key, "children" => $arrGroup];
}
$data = [
"name" => "Amalians",
"img" => "https://dl.dropboxusercontent.com/u/19954023/marvel_force_chart_img/marvel.png",
"children" => $arrGroupFormattedData
];
echo json_encode($data,JSON_PRETTY_PRINT);
You can try this:
Here you need to group the array by key year.
$array = array();
foreach ($people as $val) {
$array[$val['year']][] = $val;
}
$data['name'] = "Amalians";
$data['img'] = "https://dl.dropboxusercontent.com/u/19954023/marvel_force_chart_img/marvel.png";
$i = 0;
foreach ($array as $key => $value) {
foreach ($value as $key2 => $value2) {
$data['children'][$i]['name'] = $value2['year'];
$data['children'][$i]['children'][$key2]['SI'] = $value2['SI'];
$data['children'][$i]['children'][$key2]['name'] = $value2['name'];
$data['children'][$i]['children'][$key2]['location'] = $value2['location'];
}
$i++;
}
echo "<pre>";
echo json_encode($data, JSON_PRETTY_PRINT);
echo "</pre>";
exit();
<?php
$array = Array(Array( "SI" => 1,
"name" => Nick,
"location" => Russia,
"year" => 2011),
Array ( "SI" => 8,
"name" => Mike ,
"location" => Russia ,
"year" => 2011),
Array ( "SI" => 2,
"name" => Tom,
"location" => Russia,
"year" => 2010 ),
Array ( "SI" => 6,
"name" => Duke,
"location" => Russia ,
"year" => 2010 ) );
$json_final['child'] = array();
$temp = array();
foreach($array as $arr)
{
$flag=0;
if(!empty($json_final['child']))
{
foreach($json_final['child'] as $name_data)
{
if($name_data['name'] == $arr['year'])
{
$flag=1;
array_push($name_data['child_sub'],array("SI"=>$arr['SI'],"name"=>$arr['name'],"location"=>$arr['location']));
array_push($temp, $name_data);
}
}
}
if($flag == 0)
{
array_push($json_final['child'],array("name"=>$arr['year'],"child_sub"=>array(array("SI"=>$arr['SI'],"name"=>$arr['name'],"location"=>$arr['location']))));
}
}
$json_final['child'] = $temp;
//print_r($json_final);
echo json_encode($json_final,true)
?>
How can I add an array to array position:
Something like a:
<?php
$newArr = array('email' => array("id" => "5678", "token" => "fghjk"));
$arr = array(
"auth"=>
array(
'users'=>
array(
'id' =>"456yhjoiu",
'token' => "asdfghjkrtyui678"
)
)
);
somefunction($arr['auth'], $newArr);
I've tried array_push() but it added zero (0) before 'email' instead.~
I'm doing this to get a json output, something like this:
}
"auth": {
"users": {
"id": "456yhjoiu",
"token": "asdfghjkrtyui678"
},
"email": {
"id": "5678",
"token": "fghjk"
}
}
}
but I have this output:
{
"auth": {
"users": {
"id": "456yhjoiu",
"token": "asdfghjkrtyui678"
},
"0": {
"email": {
"id": "5678",
"token": "fghjk"
}
}
}
$data = ['auth' => array_merge($arr['auth'], $newArr)];
or old array notation <= PHP5.3
$data = array('auth' => array_merge($arr['auth'], $newArr));