Ask God for guidance

WBOY
Release: 2016-08-30 09:36:46
Original
987 people have browsed it

Ask God for guidancePicture description

Ask God for guidance

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

Reply content:

Ask God for guidancePicture description

Ask God for guidance

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>
Copy after login

Traverse such a two-dimensional array, and then return json_encode in one click. You can refer to the one upstairs

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!