• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending three arrays over json

#1
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
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.