Ich habe ein Problem, wenn Sie versuchen, mehrdimensionale Array zu JSON zu kodieren. Wie zum Entfernen der Schlüssel "0" und "1"?Kodieren multidimensionale php-Arrays zu JSON
Dies ist mein Code
$ch_name = count($app->request->post('ch_name'));
for ($i=0; $i < $ch_name; $i++) {
$min = count($app->request->post('minim_channel_'.$i));
for ($j=$min - 1; $j >= 0; $j--) {
$gros[$j] = array('min' =>$app->request->post('minim_channel_'.$i)[$j], 'price' => $app->request->post('harga_channel_'.$i)[$j]);
}
$prices[$i] = array('channel' => $app->request->post('ch_name')[$i], 'price' => $app->request->post('harsat_channel_'.$i), 'grosir' => array($gros));
}
echo json_encode($prices);
und das ist das Ergebnis
[{"channel":"Tokopedia","price":"10000","grosir":[{"1":{"min":"3","price":"9500"},"0":{"min":"10","price":"9000"}}]},{"channel":"Bukalapak","price":"10500","grosir":[{"1":{"min":"3","price":"9700"},"0":{"min":"10","price":"9200"}}]}]
Meinen Sie entfernen Sie die Schlüssel (1 und 0) in diesem Bit? "grosir": [{"1": {"min": "3", "Preis": "9700"}, "0": {"min": "10", "price": "9200"}} – Brett
versuchen Sie, '$ gros [$ j]' in '$ gros []' und '$ prices [$ i]' in '$ prices []' – Suyog