且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将多维数组转换为json格式

更新时间:2023-02-14 12:42:57

尝试一下,您可以查看实时演示

try this, you can check the live demo

<?php

    $data['post']= array(
        'title' => 'This is title',
        'message' =>'This is message',
        'datetime' => 'This is date time',
        'bannerImage' =>''
        );
    $data['author']= array(
        'authorName' => 'Jason Bourne',
        'userType' => 'Registered User',
        'address' => 'New York',
        'profilePic' => 'Profile picture'
        );
    $datas[] = $data;
    $data['post']= array(
        'title' => 'This is title1',
        'message' =>'This is message1',
        'datetime' => 'This is date time1',
        'bannerImage' =>''
        );
    $data['author']= array(
        'authorName' => 'Jason Bourne1',
        'userType' => 'Registered User1',
        'address' => 'New York1',
        'profilePic' => 'Profile picture1'
        );
    $datas[] = $data;
    $json = json_encode(array('data'=>$datas));
    echo $json;