Welcome Guest, Not a member yet? Register   Sign In
sending three arrays over json
#1

(This post was last modified: 03-29-2018, 07:54 PM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 03-30-2018, 01:18 AM by ciadmin.)

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)
Reply
#3

(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
Reply
#4

(This post was last modified: 03-30-2018, 04:05 AM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#5

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.
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB