これは$分配アレイこの場合正しい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
)
)
であり、これは非常にキーを比較し、新たな量で新しい$ responceアレイを構築IMと以下のような量0製品をフィルタリング$販売アレイ
Array
(
[ASCM72X36] => Array
(
[item_code] => ASCM72X36
[quantity] => 1.0
)
[ASCM72X60] => Array
(
[item_code] => ASCM72X60
[quantity] => 1.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エンコードを取得する必要があります3210echo json_encode($responce);
イムが出てき問題はイムJSONで.. "0"、 "2" などになっている
{"data":{"0":{"item_code":"ASCM72X36","quantity":4,"selling_price":"6758.00"},"2":{"item_code":"ASCM72X60","quantity":4,"selling_price":"8544.00"}}}
のように置きます。どのようにそれを防ぐためにそれらの "0"と "2"などなしのように置く?
{"data":{"item_code":"ASCM72X36","quantity":4,"selling_price":"6758.00"},{"item_code":"ASCM72X60","quantity":4,"selling_price":"8544.00"}}
私が見ることのできる0と2は、 "データ"配列の配列インデックスです。なぜあなたはそれらを削除したいですか? –