无法在PHP中重命名数组键

时间:2017-11-12 12:39:15

标签: php arrays laravel

我正在使用此函数创建数组:

$products = $request->input('product');
    $productinput = array();
    foreach (array_keys($products) as $fieldKey) {
        foreach ($products[$fieldKey] as $key=>$value) {
             $productinput[$key][$fieldKey] = $value;
        }
    } 
    return $productinput;

这就是它通过json_encode返回的内容:

[   
{"product_id":"63","product_batch":"BAtch1","product_quantity":"50","product_price":"200","discount":"0","net_price":"20000"},    
{"product_id":"67","product_batch":"Batch2","product_quantity":"50","product_price":"200","discount":"0","net_price":"20000"}
]

现在我需要将product_quantity重命名为quantity,将product_price重命名为price。有没有人帮助我?

0 个答案:

没有答案