Cara Mengubah Array Ke JSON pada pemrograman php

Cara mengubah format tipe data array pada php ke format data json. Berikut Kodingannya Cara Mengubah Array Ke JSON pada pemrograman php

<?php
    $arrayName = array(
        'male' => array('john','roy','ben'),
        'female' => array('marry','elli','desy'),
        'other' => array('mieke','tessy','buny'),
    );
    print_r($arrayName);
    # Array ( 
    # [male] => Array ( [0] => john [1] => roy [2] => ben ) 
    # [female] => Array ( [0] => marry [1] => elli [2] => desy ) 
    # [other] => Array ( [0] => mieke [1] => tessy [2] => buny ) )

    $json = json_encode($arrayName);
    echo $json;
    // {"male":["john","roy","ben"],
    // "female":["marry","elli","desy"],
    // "other":["mieke","tessy","buny"]}
?>

Baca Juga : Cara Menampilkan Text Pada Php

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s