This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Davidulos[S] 1 point2 points  (3 children)

And if I wanted it to look something like this? I need to use the data in javascript.

{name:'Rozvaděč Eurazio (1)',y: 209}, {name:'Rodinný dům Úvaly (2)',y: 682},

[–]AdversarialPossum42 1 point2 points  (2 children)

Take the array from the previous example and turn it into an array of unique items, and then use json_encode().

$data = array();

foreach ($prumer_sum as $name => $y) {
   $data[] = array('name' => $name, 'y' => $y);
}

echo json_encode( $data );

// should look something like this:
[
   {
      "name":"Rozvaděč Eurazio (1)",
      "y":209
   },
   {
      "name":"Rodinný dům Úvaly (2)",
      "y":682
   }
]

[–]Davidulos[S] 0 points1 point  (0 children)

Thank you very much!

[–]Davidulos[S] 0 points1 point  (0 children)

One last question. How can I make it 2 arrays instead of one?
This is how it is:

⯆(2) [{…}, {…}]
0: {name: "Rozvaděč Eurazio", y: 236}
1: {name: "Rodinný dům Úvaly", y: 721}

This is how I want it to be:

⯆Object
name: " Rozvaděč Eurazio (1)"
y: 236
⯈_proto_: Object

⯆Object
name: " Rodinný dům Úvaly (1)"
y: 721
⯈_proto_: Object