値をJSON形式にて返します。
<?php $arr = array('BTC'=> 893850, "ETH"=>93612, "XRP"=>89.00, "LTC"=> 13129.58, "DASH"=>58753.52); echo json_encode($arr); ?>
output
{“BTC”:893850,”ETH”:93612,”XRP”:89,”LTC”:13129.58,”DASH”:58753.52}
では、連想配列でみてみましょう。
<?php $arr = array( "code"=> "2317", "name"=> "システナ", "price"=>"4570", "volume"=>"492500", "index"=>array( "PER" => "37.0", "PBR" => "6.92", "rate" => "1.01" ), "url" => "https://www.systena.co.jp/" ); echo json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); ?>
{ “code”: “2317”, “name”: “システナ”, “price”: “4570”, “volume”: “492500”, “index”: { “PER”: “37.0”, “PBR”: “6.92”, “rate”: “1.01” }, “url”: “https:\/\/www.systena.co.jp\/” }