3xtr3m3d
asked on
How to get correct json output in this case?
Hi
this is the $distribution array
and this is the $sold array
so im comparing keys and building new $responce array with new quantity and filter out quantity 0 products like below
then i need to get json encode out put so im doing it like this
im getting out put like
problem is im getting a "0", "2" etc.. in json. how to prevent that and get the out put like without those "0" s and "2" etc...?
Sorry for the bad English.
Regards
this is the $distribution array
Array
(
[ASCM72X36] => Array
(
[item_code] => ASCM72X36
[quantity] => 5
[selling_price] => 6758.00
)
[ASCM72X48] => Array
(
[item_code] => ASCM72X48
[quantity] => 5
[selling_price] =>
)
[ASCM72X60] => Array
(
[item_code] => ASCM72X60
[quantity] => 5
[selling_price] => 8544.00
)
)
and this is the $sold array
Array
(
[ASCM72X36] => Array
(
[item_code] => ASCM72X36
[quantity] => 1.0
)
[ASCM72X60] => Array
(
[item_code] => ASCM72X60
[quantity] => 1.0
)
)
so im comparing keys and building new $responce array with new quantity and filter out quantity 0 products like below
$i=0;
foreach($distribution as $key => $new_distribution)
{
$newqty = $new_distribution['quantity'] - $sold[$key]['quantity'];
if( $newqty != 0 && $new_distribution['selling_price'] != ""){
$responce->data[$i]['item_code'] = $new_distribution['item_code'];
$responce->data[$i]['quantity'] = $newqty;
$responce->data[$i]['selling_price'] = $new_distribution['selling_price'];
}
$i++;
}
then i need to get json encode out put so im doing it like this
echo json_encode($responce);
im getting out put like
{"data":{"0":{"item_code":"ASCM72X36","quantity":4,"selling_price":"6758.00"},"2":{"item_code":"ASCM72X60","quantity":4,"selling_price":"8544.00"}}}
problem is im getting a "0", "2" etc.. in json. how to prevent that and get the out put like without those "0" s and "2" etc...?
{"data":{"item_code":"ASCM72X36","quantity":4,"selling_price":"6758.00"},{"item_code":"ASCM72X60","quantity":4,"selling_price":"8544.00"}}
Sorry for the bad English.
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Slick812: ya with those indices im having problem loading a Extjs store.
anyway this solved my problem
Open in new window
Thanks