# データ整形して出力(prettify)

# PHP

var_dump($o)
json_encode($o, JSON_PRETTY_PRINT);
$man = [ 'name' => 'taro', 'age' => 15, 'skills' => ['sing', 'dance'] ];

echo $man . "\n";               # => Array
echo json_encode($man) . "\n";  # => {"name":"taro","age":15,"skills":["sing","dance"]}
var_dump($man);
array(3) {
      ["name"]=>
      string(4) "taro"
      ["age"]=>
      int(15)
      ["skills"]=>
      array(3) {
        [0]=>
        string(4) "sing"
        [1]=>
        string(5) "dance"
      }
    }

# Python

pprint.pprint(o)
print(json.encode(o, indent=2))
import pprint

man = { 'name' : 'taro', 'age' : 15, 'skills' : ['sing', 'dance'] }
print man          # => {'skills': ['sing', 'dance', 'age': 15, 'name': 'taro'}
pprint.pprint(man) # => {'age': 15, 'name': 'taro', 'skills': ['sing', 'dance']}

# Ruby

p o
pp o
require 'pp'

man = { name: 'taro', age: 15, skills: ['sing', 'dance'] }

puts man  # => {:name=>"taro", :age=>15, :skills=>["sing", "dance"]}
p man     # => {:name=>"taro", :age=>15, :skills=>["sing", "dance"]}
pp man    # => {:name=>"taro", :age=>15, :skills=>["sing", "dance"]}

# この例だと違いが分からないけど、pp は より詳しい出力が出たり、改行してくれたりする。たぶん。

[ 📩 ご意見 ]