use Symfony\Component\Yaml\Yaml; // Parse the YAML file into an array $data = Yaml::parse(file_get_contents('config.yml')); // Access a value in the array echo $data['database']['host'];
use Symfony\Component\Yaml\Yaml; // An array of data $data = [ 'database' => [ 'host' => 'localhost', 'port' => '3306', 'username' => 'root', 'password' => 'secret', 'database' => 'myDatabase' ], 'debug' => true, 'cache_dir' => '/tmp/cache' ]; // Dump the data to a YAML file file_put_contents('config.yml', Yaml::dump($data));In this example, we have an array containing some configuration data, and we use the dump() method to write it to a config.yml file. This package is a YAML parser and dumper library.