这是$分布阵列如何在这种情况下获得正确的json输出?
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
)
)
,这是$出售阵列
Array
(
[ASCM72X36] => Array
(
[item_code] => ASCM72X36
[quantity] => 1.0
)
[ASCM72X60] => Array
(
[item_code] => ASCM72X60
[quantity] => 1.0
)
)
这样的IM比较键和建立新的$性反应的数组新的数量,并筛选出数量一样低于0产品
$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++;
}
然后我需要得到JSON编码出来把这样的IM做这样
echo json_encode($responce);
即时得到了让像
{"data":{"0":{"item_code":"ASCM72X36","quantity":4,"selling_price":"6758.00"},"2":{"item_code":"ASCM72X60","quantity":4,"selling_price":"8544.00"}}}
问题是即时得到一个 “0”, “2” 等。在JSON。如何防止那些“0”和“2”等等......?
{"data":{"item_code":"ASCM72X36","quantity":4,"selling_price":"6758.00"},{"item_code":"ASCM72X60","quantity":4,"selling_price":"8544.00"}}
的0和2从我可以看到是“数据”数组的数组索引。你为什么要删除它们? –