CodeIgniter Forums
sending three arrays over json - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: sending three arrays over json (/showthread.php?tid=70357)



sending three arrays over json - richb201 - 03-29-2018

I have 3, one dimensional arrays, $PR, $AC, and $BC that I want to json_encode and send as one unit back to my browser app:
$this->output
 ->set_content_type('application/json')
 ->set_output(json_encode($data));

I thought I could combine them with $data=$BC+$AC+$PR but that is not working. On the client side I am just seeing $BC. Can I create a three d array and send it over the link?

I also want to send a checksum. Any way to create this checksum?


RE: sending three arrays over json - XtreemDeveloper - 03-29-2018

You can send three array by single data array using this code.

$data['BC'] = $BC;
$data['BC'] = $BC;
$data['PR'] = $PR;
$this->output
->set_content_type('application/json')
->set_output(json_encode($data));

By:Xtreem Solution

**SEO link redacted**

[Dedicated PHP Developer](https://xtreemsolution.com/hire-php-developer.html)


RE: sending three arrays over json - Paradinight - 03-29-2018

(03-29-2018, 07:53 PM)richb201 Wrote: I have 3, one dimensional arrays, $PR, $AC, and $BC that I want to json_encode and send as one unit back to my browser app:
$this->output
 ->set_content_type('application/json')
 ->set_output(json_encode($data));

I thought I could combine them with $data=$BC+$AC+$PR but that is not working. On the client side I am just seeing $BC. Can I create a three d array and send it over the link?

I also want to send a checksum. Any way to create this checksum?

Show us the content of the $PR, $AC, and $BC array.

http://php.net/manual/en/function.array-merge.php
http://php.net/manual/en/language.operators.array.php


RE: sending three arrays over json - richb201 - 03-30-2018

They are strings that are coming out of three separate tables. I was thinking a 2 d array since I need to keep them separate for use on the client side. so $PR= ["go shopping", "get gas", "wash windows"]
 and    $AC= ["bake bread", "juliane carrots"]

                                   columns
index
0             "go shopping"            "bake bread"
1                "get gas"              "juliane carrots"
2               "wash windows"


So I know that in a zero based system column 0 is for homemaint and I know column 1 is for cooking

array[1][1] = "juliene carrots"

This was a basic data structure 30 years ago when I went to school. Is it not so easy in PHP? I tried to push them onto a list with push_array() but I am not sure there are two d arrays in php. Is there an easier way to do it?


RE: sending three arrays over json - richb201 - 03-30-2018

Thanks Guys. I got a solution. There are 2 d arrays in PHP! Seems that there is no need to declare them like that. Just use them that way and they work. I declared $table-array(); and later assigned to it array[x][y]="foo", using x as the column.