Picture description
I received the cart_id from ios in the form of an array, and then returned the data to it after foreach traversal. How can I return the data in the format shown in the picture? Can anyone please guide me
Picture description
I received the cart_id from ios in the form of an array, and then returned the data to it after foreach traversal. How can I return the data in the format shown in the picture? Can anyone please guide me
<code class="php"> //封装数据集合 $data = []; foreach ($cart_id as $key => $val) { // 其他逻辑得到你想要的数据 // $service_name = $serviceSqlResult['service_name']; $service_price = $serviceSqlResult['service_price']; $service_num = $serviceSqlResult['service_num']; $ipde_img = $serviceSqlResult['ipde_img']; $data[] = [ 'service_name' => $service_name, 'service_price' => $service_price, 'service_num' => $service_num, 'ipde_img' => $ipde_img, ]; } //输出 echo json_encode($data);</code>
Traverse such a two-dimensional array, and then return json_encode
in one click. You can refer to the one upstairs