<?php // read YAML library require 'vendor/autoload.php'; use Symfony\Component\Yaml; // declare data $data = [ 'Taro'=>['age'=>30, 'hobby'=>['Guitar','Piano']], 'Takeshi'=>['age'=>18, 'hobby'=>['Reading']], 'Arisa'=>['age'=>16, 'hobby'=>['Walking','Tea']], 'Sara'=>['age'=>22, 'hobby'=>['Sleeping']] ]; $file = "serialize-test.yaml"; $dumper = new Yalm\Dumper(); $yaml = $dumper->dump($data); file_put_contents($file, $yaml); $yaml2 = file_get_contents($file); $yaml_p = new Yaml\Parser(); $data2 = $yaml_p->parse($yam12); foreach ($data2 as $name => $v) { $age = $v["age"]; $hobby = $v["hobby"][0]; if (isset($v["hobby"][1])){ $hobby .= " ".$v["hobby"][1]; } echo "[$name] $age $hobby\n"; }