Currently my JSON outputs from the following PHP:
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => $desc,
'price' => $price,
'special' => $special,
'tax' => $tax,
);
And with this ($products = json_encode ($data['products']);
) produces the following:
[{"product_id":"28",
"thumb":"x",
"name":"name",
"description":"abc",
"price":"$123.00",
"special":false,
"tax":"$100.00"}]
Is it possible to delete the names without modifying the php "$data['products'][] = array();
"? I am trying to achieve:
["28",
"x",
"name",
"abc",
"$123.00",
false,
"$100.00"]
First time ever using JSON encode so any other advice would be awesome!
You can use array_map
to loop thru your array and use array_values
as callback function to convert the associative array to simple array
$arr = array_map('array_values', $data['products'] );
$products = json_encode ($arr);
This will result to:
[["28","x","name","abc","$123.00",false,"$100.00"]]
You can use array_values
to get the values of the first/only entry in $data['products']
, and then encode that:
$json = json_encode(array_values($data['products'][0]));
That produces
["28","x","name","abc","$123.00",false,"$100.00"]