I have a PHP function that's being called from an angularjs codebase via ajax. The data that's returned contains multidimensional arrays, nested arrays, all kinds of arrays.
This is how the data looks in the network tab of Chrome's dev tools; sorry for the screenshot but I can't seem to get the actual data to paste correctly:
What our angular dev wants is for the options to be arrays, not objects. This is the sample he provided:
selects: [
{
name: 'prod',
options: [
{
text: 'What Flavor?'
val: 'default_text'
},
{
oop: false,
text: 'Honey Bbq',
val: 'HO'
}]
}
]
This is what my print_r
looks like. How can I change the format of my array to give the angular dev what he needs? I've tried using json_encode
, but that ends up setting the entire value of options
to be a quoted string of json, rather than an array.
[selects] => Array
(
[0] => Array
(
[name] => prod
[default] => What Flavor?
[options] => Array
(
[0] => Array
(
[val] => default_text
[text] => What Flavor?
[oop] =>
)
[1] => Array
(
[val] => HQ
[text] => Honey Bbq
[oop] =>
)
)
)
)