Pop\Data\Type\Yaml::encode PHP Метод

encode() публичный статический Метод

Encode the data into its native format.
public static encode ( mixed $data ) : string
$data mixed
Результат string
    public static function encode($data)
    {
        $yaml = "%YAML 1.1\n---\n";
        foreach ($data as $key => $ary) {
            foreach ($ary as $k => $v) {
                $yaml .= " " . $k . ": \"" . addslashes($v) . "\"\n";
            }
            $yaml .= "-\n";
        }
        return $yaml;
    }

Usage Example

Пример #1
0
 public function testEncode()
 {
     $ary = array(array('Name' => 'Test1', 'Num' => 1), array('Name' => 'Test2', 'Num' => 2));
     $y = Yaml::encode($ary);
     $this->assertContains('Name: "Test1"', $y);
 }