{"id":22328143,"url":"https://github.com/shimabox/smbarrayto","last_synced_at":"2026-05-14T21:05:47.069Z","repository":{"id":55590167,"uuid":"76714978","full_name":"shimabox/SMBArrayto","owner":"shimabox","description":"Array to csv, tsv, ltsv, xml, json, ...","archived":false,"fork":false,"pushed_at":"2020-12-20T03:32:14.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T08:14:24.006Z","etag":null,"topics":["csv","json","ltsv-format","tsv","xml"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shimabox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-17T09:21:24.000Z","updated_at":"2020-12-20T03:23:28.000Z","dependencies_parsed_at":"2022-08-15T03:50:35.392Z","dependency_job_id":null,"html_url":"https://github.com/shimabox/SMBArrayto","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimabox%2FSMBArrayto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimabox%2FSMBArrayto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimabox%2FSMBArrayto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimabox%2FSMBArrayto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shimabox","download_url":"https://codeload.github.com/shimabox/SMBArrayto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245600166,"owners_count":20642253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","json","ltsv-format","tsv","xml"],"created_at":"2024-12-04T03:11:43.068Z","updated_at":"2025-10-24T12:01:54.357Z","avatar_url":"https://github.com/shimabox.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SMBArrayto\n[![License](https://poser.pugx.org/shimabox/smbarrayto/license)](https://packagist.org/packages/shimabox/smbarrayto)\n[![Build Status](https://travis-ci.org/shimabox/SMBArrayto.svg?branch=master)](https://travis-ci.org/shimabox/SMBArrayto)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f9303def15fbfc74d3f5/maintainability)](https://codeclimate.com/github/shimabox/SMBArrayto/maintainability)\n[![Coverage Status](https://coveralls.io/repos/github/shimabox/SMBArrayto/badge.svg?branch=master)](https://coveralls.io/github/shimabox/SMBArrayto?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/shimabox/smbarrayto/v/stable)](https://packagist.org/packages/shimabox/smbarrayto)\n[![Latest Unstable Version](https://poser.pugx.org/shimabox/smbarrayto/v/unstable)](https://packagist.org/packages/shimabox/smbarrayto)\n\nArray to csv, tsv, ltsv, xml, json, ...\n\n## Overview\n\n- Array to csv, tsv, ltsv, xml, json, ...\n- And provides a download function, output function, write function\n\n## Requirements\n\n- PHP 5.4+ or newer\n- [Composer](https://getcomposer.org)\n- [GitHub - fjyuu/monolog-ltsv-formatter: LTSV Formatter for Monolog](https://github.com/fjyuu/monolog-ltsv-formatter)\n- [GitHub - spatie/array-to-xml: A simple class to convert an array to xml](https://github.com/spatie/array-to-xml)\n\n## Installation\n\n```\ncomposer require shimabox/smbarrayto\n```\n\n## Basic Usage\n\n### In the case of csv download\n\n- It does not create the actual file\n  - It makes use of the temporary file\n- Use the header function\n\n```php\n\u003c?php\nrequire_once '/your/path/to/vendor/autoload.php';\n\nuse SMB\\Arrayto;\n\n$header = ['name', '名前', 'price'];\n\n$rows = [\n    ['apple', 'りんご', '1,000'],\n    ['pineapple', 'パインアップル', '800']\n];\n\n// csv\n$csv = Arrayto\\Csv::factory();\n\n// downloader object\n$csvDownloader = $csv-\u003egetDownloader();\n\n// download\n$csvDownloader-\u003esetHeader($header) // optional\n              -\u003esetRows($rows) // set the rows\n              -\u003edownload('example.csv');\nexit;\n```\n\nor\n\n```php\n\u003c?php\nrequire_once '/your/path/to/vendor/autoload.php';\n\nuse SMB\\Arrayto;\n\n$header = ['name', '名前', 'price'];\n\n// csv\n$csv = Arrayto\\Csv::factory();\n\n// downloader object\n$csvDownloader = $csv-\u003egetDownloader();\n\n// download\n$csvDownloader-\u003esetHeader($header) // optional\n              -\u003eaddRow(['apple', 'りんご', '1,000']) // add the row\n              -\u003eaddRow(['pineapple', 'パインアップル', '800']) // add the row\n              -\u003edownload('example.csv');\nexit;\n```\n\n#### Result\n\n```csv\nname,名前,price\napple,りんご,\"1,000\"\npineapple,パインアップル,800\n```\n\n- The default line feed code ```CRLF``` (only csv, tsv)\n- The default encoding ```SJIS-win``` (only csv, tsv)\n- Please perform the following if you want to change this\n- e.g.)\n```php\n  // download\n  $csvDownloader-\u003esetHeader($header)\n                -\u003esetRows($rows)\n                -\u003esetToConvert(false) // Not carried out the convert\n                -\u003edownload('example.csv');\n  exit;\n```\n  - Line feed code is ```LF```\n  - Encoding is ```UTF-8```\n\n## Example\n\n- Use basically the following three interfaces\n  - ```download($fileName);```\n    - It does not create the actual file　(csv, tsv)\n      - It makes use of the temporary file\n    - Use the header function\n  - ```output();```\n    - It does not create the actual file　(csv, tsv)\n      - It makes use of the temporary file\n    - Use the header function\n    - Simply echo()\n  - ```write();```\n    - Need to specify the path where you want to save by setFileName()\n\n### In the case of CSV\n\n**download($fileName);**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n$csvHeader = ['name', '名前', 'price'];\n\n$csvRows = [\n    ['apple', 'りんご', '1,000'],\n    ['pineapple', 'パインアップル', '800']\n];\n\n// csv\n$csv = Arrayto\\Csv::factory();\n\n// downloader object\n$csvDownloader = $csv-\u003egetDownloader();\n\n// download\n$csvDownloader-\u003esetHeader($csvHeader)\n              -\u003esetRows($csvRows)\n              -\u003edownload('example.csv');\nexit;\n```\n\n**output();**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n// csv\n$csv = Arrayto\\Csv::factory();\n\n// outputter object\n$csvOutputter = $csv-\u003egetOutputter();\n\n// output\n$csvOutputter-\u003esetHeader($csvHeader)\n             -\u003esetRows($csvRows)\n             -\u003eoutput();\nexit;\n```\n\n**write();**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n// csv\n$csv = Arrayto\\Csv::factory();\n\n// writer object\n$csvWriter = $csv-\u003egetWriter();\n\n// write\n$csvWriter-\u003esetHeader($csvHeader)\n          -\u003esetRows($csvRows)\n          -\u003esetFileName('/path/to/your/example.csv') // specify the path\n          -\u003ewrite();\n```\n\n### In the case of TSV\n\n- With csv interface\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n$header = ['name', '名前', 'price'];\n\n$rows = [\n    ['apple', 'りんご', '1,000'],\n    ['pineapple', 'パインアップル', '800']\n];\n\n// tsv\n$tsv = Arrayto\\Tsv::factory();\n\n// downloader object\n$tsvDownloader = $tsv-\u003egetDownloader();\n\n// outputter object\n$tsvOutputter = $tsv-\u003egetOutputter();\n\n// writer object\n$tsvWriter = $tsv-\u003egetWriter();\n```\n\n#### CSV, TSV configuration\n\n- ``` setHeader(array $header); ```\n  - You can set the header row\n- ``` clearHeader(); ```\n  - You can clear the header row\n- ``` setToConvert($toConvert); ```\n  - The default is ```true```\n    - Convert the line feed code to ```CRLF```\n    - To convert the encoding to ```SJIS-win```\n  - If you set the ```false```, it does not perform the conversion\n\n### In the case of LTSV\n\n- It depends on [GitHub - fjyuu/monolog-ltsv-formatter: LTSV Formatter for Monolog](https://github.com/fjyuu/monolog-ltsv-formatter)\n\n**download($fileName);**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n$obj = new \\stdClass();\n$obj-\u003ehoge = 123;\n$obj-\u003epiyo = ['abc' =\u003e null, 'def' =\u003e false];\n\n$ltsvRows = [\n    'time' =\u003e \"[2017-01-01 08:59:60]\",\n    'foo' =\u003e null,\n    'bar' =\u003e true,\n    'buz' =\u003e 0,\n    'url' =\u003e 'http://example.net',\n    'arr' =\u003e ['foo' =\u003e 'bar'],\n    'obj' =\u003e $obj\n];\n\n// ltsv\n$ltsv = Arrayto\\Ltsv::factory();\n\n// downloader object\n$ltsvDownloader = $ltsv-\u003egetDownloader();\n\n// download\n$ltsvDownloader-\u003esetRows($ltsvRows)\n               -\u003edownload('example.log');\nexit;\n```\n\n**Result**\n\n```\ntime:[2017-01-01 08:59:60]\u003cTAB\u003efoo:NULL\u003cTAB\u003ebar:true\u003cTAB\u003ebuz:0\u003cTAB\u003eurl:http://example.net\u003cTAB\u003earr:{\"foo\":\"bar\"}\u003cTAB\u003eobj:[object] (stdClass: {\"hoge\":123,\"piyo\":{\"abc\":null,\"def\":false}})\n```\n\n**output();**\n\n- **It does nothing**\n\n**write();**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n// ltsv\n$ltsv = Arrayto\\Ltsv::factory();\n\n// writer object\n$ltsvWriter = $ltsv-\u003egetWriter();\n\n// write\n$ltsvWriter-\u003esetRows($ltsvRows)\n           -\u003esetFileName('/path/to/your/example.log') // specify the path\n           -\u003ewrite();\n```\n\n#### LTSV configuration\n\n- ``` overrideEOL($EOL); ```\n  - You can override the line feed code\n  - The default line feed code is ``` \\n (LF) ```\n  - e.g.)\n  ```php\n  // write\n  $ltsvWriter-\u003esetRows($ltsvRows)\n             -\u003esetFileName('/path/to/your/example.log')\n             -\u003eoverrideEOL(\"\\r\\n\") // CRLF\n             -\u003ewrite();\n  ```\n\n### In the case of XML\n\n- It depends on [GitHub - spatie/array-to-xml: A simple class to convert an array to xml](https://github.com/spatie/array-to-xml)\n\n**download($fileName);**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n$xmlRows['book'] = [\n    [\n        '_attributes' =\u003e ['category' =\u003e 'children', 'currency' =\u003e 'USD'],\n        'tilte' =\u003e [\n            '_attributes' =\u003e ['lang' =\u003e 'en'],\n            '_value' =\u003e 'Harry Potter'\n        ],\n        'author' =\u003e 'J K. Rowling',\n        'year' =\u003e 2005,\n        'price' =\u003e 29.99\n    ],\n    [\n        '_attributes' =\u003e ['category' =\u003e 'music', 'currency' =\u003e 'JPY'],\n        'tilte' =\u003e [\n            '_attributes' =\u003e ['lang' =\u003e 'ja'],\n            '_value' =\u003e '[score] Boys\u0026Gilrs'\n        ],\n        'author' =\u003e 'GOING STEADY(銀杏BOYZ)',\n        'year' =\u003e 2000,\n        'price' =\u003e \"2,808\"\n    ]\n];\n\n// xml\n$xml = Arrayto\\Xml::factory();\n\n// downloader object\n$xmlDownloader = $xml-\u003egetDownloader();\n\n// download\n$xmlDownloader-\u003esetRows($xmlRows)\n              -\u003esetRootElementName('bookstore') // optional\n              -\u003edownload('example.xml');\nexit;\n```\n\n**Result**\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cbookstore\u003e\n  \u003cbook category=\"children\" currency=\"USD\"\u003e\n    \u003ctilte lang=\"en\"\u003eHarry Potter\u003c/tilte\u003e\n    \u003cauthor\u003eJ K. Rowling\u003c/author\u003e\n    \u003cyear\u003e2005\u003c/year\u003e\n    \u003cprice\u003e29.99\u003c/price\u003e\n  \u003c/book\u003e\n  \u003cbook category=\"music\" currency=\"JPY\"\u003e\n    \u003ctilte lang=\"ja\"\u003e[score] Boys\u0026amp;Gilrs\u003c/tilte\u003e\n    \u003cauthor\u003eGOING STEADY(銀杏BOYZ)\u003c/author\u003e\n    \u003cyear\u003e2000\u003c/year\u003e\n    \u003cprice\u003e2,808\u003c/price\u003e\n  \u003c/book\u003e\n\u003c/bookstore\u003e\n```\n\n**output();**\n\n- **It does nothing**\n\n**write();**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n// xml\n$xml = Arrayto\\Xml::factory();\n\n// writer object\n$xmlWriter = $xml-\u003egetWriter();\n\n// write\n$xmlWriter-\u003esetRows($xmlRows)\n          -\u003esetRootElementName('bookstore') // optional\n          -\u003esetFileName('/path/to/your/example.xml') // specify the path\n          -\u003ewrite();\n```\n\n#### XML configuration\n\n- ``` setRootElementName($name); ```\n  - You can set the root element name\n  - Default of the root element name is the ```root```\n- ``` setReplaceSpacesByUnderScoresInKeyNames($bool); ```\n  - Set to enable replacing space with underscore\n  - The default is ```true```\n- ``` toFormatOutput($toFormatOutput); ```\n  - Nicely formats output with indentation and extra space\n  - The default is ```true```\n  - If you set the ```false```, it does not format\n  - e.g.)\n  ```php\n    $xmlWriter-\u003esetRows($xmlRows)\n              -\u003esetRootElementName('bookstore') // optional\n              -\u003esetFileName('example.xml') // specify the path\n              -\u003etoFormatOutput(false) // it does not format\n              -\u003ewrite();\n  ```\n  **Result**\n  ```xml\n  \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n  \u003cbookstore\u003e\u003cbook category=\"children\" currency=\"USD\"\u003e\u003ctilte lang=\"en\"\u003eHarry Potter\u003c/tilte\u003e\u003cauthor\u003eJ K. Rowling\u003c/author\u003e\u003cyear\u003e2005\u003c/year\u003e\u003cprice\u003e29.99\u003c/price\u003e\u003c/book\u003e\u003cbook category=\"music\" currency=\"JPY\"\u003e\u003ctilte lang=\"ja\"\u003e[score] Boys\u0026amp;Gilrs\u003c/tilte\u003e\u003cauthor\u003eGOING STEADY(銀杏BOYZ)\u003c/author\u003e\u003cyear\u003e2000\u003c/year\u003e\u003cprice\u003e2,808\u003c/price\u003e\u003c/book\u003e\u003c/bookstore\u003e\n  ```\n\n### In the case of Json\n\n**download($fileName)**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n$obj = new \\stdClass();\n$obj-\u003ehoge = '123';\n$obj-\u003epiyo = ['abc' =\u003e null, 'def' =\u003e false];\n\n$jsonRows = [\n    ['key1' =\u003e null, 'key2' =\u003e true, 'key3' =\u003e 0],\n    ['url' =\u003e 'http://example.net'],\n    ['arr' =\u003e ['foo' =\u003e 'bar']],\n    ['obj' =\u003e $obj]\n];\n\n// json\n$json = Arrayto\\Json::factory();\n\n// downloader object\n$jsonDownloader = $json-\u003egetDownloader();\n\n// download\n$jsonDownloader-\u003esetRows($jsonRows)\n               -\u003edownload('example.json');\nexit;\n```\n\n**Result**\n\n```json\n[\n    {\n        \"key1\": null,\n        \"key2\": true,\n        \"key3\": 0\n    },\n    {\n        \"url\": \"http://example.net\"\n    },\n    {\n        \"arr\": {\n            \"foo\": \"bar\"\n        }\n    },\n    {\n        \"obj\": {\n            \"hoge\": \"123\",\n            \"piyo\": {\n                \"abc\": null,\n                \"def\": false\n            }\n        }\n    }\n]\n```\n\n**output();**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n// json\n$json = Arrayto\\Json::factory();\n\n// outputter object\n$jsonOutputter = $json-\u003egetOutputter();\n\n// output\n$jsonOutputter-\u003esetRows($jsonRows)\n              -\u003eoutput();\nexit;\n```\n\n**write();**\n\n```php\n\u003c?php\nuse SMB\\Arrayto;\n\n// json\n$json = Arrayto\\Json::factory();\n\n// writer object\n$jsonWriter = $json-\u003egetWriter();\n\n// write\n$jsonWriter-\u003esetRows($jsonRows)\n           -\u003esetFileName('/path/to/your/example.json') // specify the path\n           -\u003ewrite();\n```\n\n#### JSON configuration\n\n- ``` setJsonEncodeOption($option); ```\n  - You can override the json_encode options\n    - [PHP: json_encode - Manual](http://php.net/manual/en/function.json-encode.php \"PHP: json_encode - Manual\") - options\n  - The default is ```448 (JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)```\n  - e.g.)\n  ```php\n    $jsonWriter-\u003esetRows($jsonRows)\n               -\u003esetFileName('/path/to/your/example.json') // specify the path\n               -\u003esetJsonEncodeOption(JSON_FORCE_OBJECT) // override\n               -\u003ewrite();\n  ```\n  **Result**\n  ```json\n    {\"0\":{\"key1\":null,\"key2\":true,\"key3\":0},\"1\":{\"url\":\"http:\\/\\/example.net\"},\"2\":{\"arr\":{\"foo\":\"bar\"}},\"3\":{\"obj\":{\"hoge\":\"123\",\"piyo\":{\"abc\":null,\"def\":false}}}}\n  ```\n\n### Other functions of the Downloader\n\n- ``` downloadExistsFile($fileName, $aliasOfFileName = ''); ```\n  - Download an existing file\n  ```php\n    \u003c?php\n    use SMB\\Arrayto;\n\n    // csv\n    $csv = Arrayto\\Csv::factory();\n\n    // downloader object\n    $csvDownloader = $csv-\u003egetDownloader();\n\n    // download an existing file\n    $csvDownloader-\u003edownloadExistsFile('/path/to/your/example.csv'); // file name is example.csv\n\n    // or download an existing file as an alias\n    $csvDownloader-\u003edownloadExistsFile('/path/to/your/example.csv', 'sample.csv'); // file name is sample.csv\n\n    exit;\n  ```\n- ``` downloadExistsFileUsingWriter($fileName, Writable $writer); ```\n  - Download an existing file using Writer\n  - Download after the writing of the file\n  ```php\n    \u003c?php\n    use SMB\\Arrayto;\n\n    $rows = [\n        ['apple', 'りんご', '1,000'],\n        ['pineapple', 'パインアップル', '800']\n    ];\n\n    // csv\n    $csv = Arrayto\\Csv::factory();\n\n    // writer object\n    $csvWriter = $csv-\u003egetWriter()\n                     -\u003esetRows($rows)\n                     -\u003esetFileName('/path/to/your/example.csv'); // specify the path\n\n    // downloader object\n    $csvDownloader = $csv-\u003egetDownloader();\n\n    // download after the writing of the file\n    $csvDownloader-\u003edownloadExistsFileUsingWriter('sample.csv', $csvWriter); // file name is sample.csv\n\n    exit;\n  ```\n\n### Configuration\n\n@see ``` SMB\\Arrayto\\Traits\\Storable　```\n\n- ``` addRow($row); ```\n  - Add the row\n  ```php\n  use SMB\\Arrayto;\n\n  $obj = new \\stdClass();\n  $obj-\u003ehoge = '123';\n  $obj-\u003epiyo = ['abc' =\u003e null, 'def' =\u003e false];\n\n  // json\n  $json = Arrayto\\Json::factory();\n\n  // write\n  $json-\u003egetWriter()\n\t   -\u003eaddRow(['key1' =\u003e null, 'key2' =\u003e true, 'key3' =\u003e 0])\n       -\u003eaddRow(['url' =\u003e 'http://example.net'])\n       -\u003eaddRow(['arr' =\u003e ['foo' =\u003e 'bar']])\n       -\u003eaddRow(['obj' =\u003e $obj])\n       -\u003esetFileName('/path/to/your/example.json')\n       -\u003ewrite();\n  ```\n  **Result**\n  ```json\n  [\n      {\n          \"key1\": null,\n          \"key2\": true,\n          \"key3\": 0\n      },\n      {\n          \"url\": \"http://example.net\"\n      },\n      {\n          \"arr\": {\n              \"foo\": \"bar\"\n          }\n      },\n      {\n          \"obj\": {\n              \"hoge\": \"123\",\n              \"piyo\": {\n                  \"abc\": null,\n                  \"def\": false\n              }\n          }\n      }\n  ]\n  ```\n- ``` addRowBySpecifyingKV($key, $value); ```\n  - To add a specified row keys and values\n  ```php\n    \u003c?php\n    use SMB\\Arrayto;\n\n    $obj = new \\stdClass();\n    $obj-\u003ehoge = '123';\n    $obj-\u003epiyo = ['abc' =\u003e null, 'def' =\u003e false];\n\n    $obj2 = new \\stdClass();\n    $obj2-\u003ehoge = '456';\n    $obj2-\u003epiyo = ['ghi' =\u003e null, 'jkl' =\u003e false];\n\n    // json\n    $json = Arrayto\\Json::factory();\n\n    // write\n    $json-\u003egetWriter()\n         -\u003eaddRowBySpecifyingKV('url', 'http://example.net')\n         -\u003eaddRowBySpecifyingKV('url', 'http://example.org')\n         -\u003eaddRowBySpecifyingKV('arr', ['foo' =\u003e 'bar'])\n         -\u003eaddRowBySpecifyingKV('arr', ['baz' =\u003e 'fuga'])\n         -\u003eaddRowBySpecifyingKV('obj', $obj)\n         -\u003eaddRowBySpecifyingKV('obj', $obj2)\n         -\u003esetFileName('/path/to/your/example.json')\n         -\u003ewrite();\n  ```\n  **Result**\n  ```json\n    {\n        \"url\": [\n            \"http://example.net\",\n            \"http://example.org\"\n        ],\n        \"arr\": [\n            {\n                \"foo\": \"bar\"\n            },\n            {\n                \"baz\": \"fuga\"\n            }\n        ],\n        \"obj\": [\n            {\n                \"hoge\": \"123\",\n                \"piyo\": {\n                    \"abc\": null,\n                    \"def\": false\n                }\n            },\n            {\n                \"hoge\": \"456\",\n                \"piyo\": {\n                    \"ghi\": null,\n                    \"jkl\": false\n                }\n            }\n        ]\n    }\n  ```\n- ``` setAllowDuplicateKey($toAllow); ```\n  - Whether set to allow duplicate keys\n  - The default is ```true```\n    - csv,tsv behaves as false\n  - If you set the ```false```, it does not allow duplicate keys\n  - e.g.)\n  ```php\n    \u003c?php\n    use SMB\\Arrayto;\n\n    $obj = new \\stdClass();\n    $obj-\u003ehoge = '123';\n    $obj-\u003epiyo = ['abc' =\u003e null, 'def' =\u003e false];\n\n    $obj2 = new \\stdClass();\n    $obj2-\u003ehoge = '456';\n    $obj2-\u003epiyo = ['ghi' =\u003e null, 'jkl' =\u003e false];\n\n    // json\n    $json = Arrayto\\Json::factory();\n\n    // write\n    $json-\u003egetWriter()\n         -\u003esetAllowDuplicateKey(false) // it does not allow duplicate keys\n         -\u003eaddRowBySpecifyingKV('url', 'http://example.net')\n         -\u003eaddRowBySpecifyingKV('url', 'http://example.org')\n         -\u003eaddRowBySpecifyingKV('arr', ['foo' =\u003e 'bar'])\n         -\u003eaddRowBySpecifyingKV('arr', ['baz' =\u003e 'fuga'])\n         -\u003eaddRowBySpecifyingKV('obj', $obj)\n         -\u003eaddRowBySpecifyingKV('obj', $obj2)\n         -\u003esetFileName('/path/to/your/example.json')\n         -\u003ewrite();\n  ```\n  **Result**\n  ```json\n    {\n        \"url\": \"http://example.org\",\n        \"arr\": {\n            \"baz\": \"fuga\"\n        },\n        \"obj\": {\n            \"hoge\": \"456\",\n            \"piyo\": {\n                \"ghi\": null,\n                \"jkl\": false\n            }\n        }\n    }\n  ```\n\n### Configuration for write\n\n@see ``` SMB\\Arrayto\\Traits\\File```\n\n- ``` setFileName($fileName); ```\n  - Specify where to save the file path (is a required value)\n  - ``` '/path/to/your/example.csv' ``` or ``` '../example.csv' ``` or ``` 'example.csv' ``` ...\n- ``` setOpenMode($mode); ```\n  - Specify the open mode of the file\n  - The default open mode is ``` w ```\n  - [PHP: fopen - Manual](http://php.net/manual/en/function.fopen.php \"PHP: fopen - Manual\") - A list of possible modes for fopen()\n  - e.g.)\n  ```php\n    \u003c?php\n    use SMB\\Arrayto;\n\n    $header = ['name', '名前', 'feature'];\n\n    $rows1 = [\n        ['apple', 'りんご', \"Sweet\\tRed\"]\n    ];\n\n    // tsv\n    $tsv = Arrayto\\Tsv::factory();\n\n    // writer object\n    $tsvWriter = $tsv-\u003egetWriter();\n\n    $tsvWriter-\u003esetHeader($header)\n              -\u003esetRows($rows1)\n              -\u003esetFileName('/path/to/your/example.tsv')\n              -\u003ewrite();\n\n    $rows2 = [\n        ['pineapple', 'パインアップル', \"Sour\\tYellow\"]\n    ];\n    $tsvWriter-\u003eclearHeader()\n             -\u003esetRows($rows2)\n             -\u003esetOpenMode('a') // set open mode 'a'\n             -\u003ewrite();\n\n    $rows3 = [\n        ['orange', 'オレンジ', \"Juicy\\tOrange\"]\n    ];\n    $tsvWriter-\u003esetRows($rows3)\n              -\u003ewrite();\n  ```\n  **Result**\n  ```tsv\n    name\u003cTAB\u003e名前\u003cTAB\u003efeature\n    apple\u003cTAB\u003eりんご\u003cTAB\u003e\"Sweet\u003cTAB\u003eRed\"\n    pineapple\u003cTAB\u003eパインアップル\u003cTAB\u003e\"Sour\u003cTAB\u003eYellow\"\n    orange\u003cTAB\u003eオレンジ\u003cTAB\u003e\"Juicy\u003cTAB\u003eOrange\"\n  ```\n- ``` setPermission($permission); ```\n  - You can set the file permissions\n  - The default permission is ```666```\n  - e.g.)\n  ```php\n    $csvWriter-\u003esetRows($rows)\n              -\u003esetPermission(777) // set the permissions to 777\n              -\u003ewrite();\n  ```\n\n### Other methods of instantiation\n\n- ``` Arrayto::factory(XXX); ```\n```php\n  \u003c?php\n  use SMB\\Arrayto;\n\n  $csv = Arrayto::factory(Arrayto::CSV);   // =\u003e SMB\\Arrayto\\Csv\n  // $csv == Arrayto\\Csv::factory();\n\n  $tsv = Arrayto::factory(Arrayto::TSV);   // =\u003e SMB\\Arrayto\\Tsv\n  // $tsv == Arrayto\\Tsv::factory();\n\n  $ltsv = Arrayto::factory(Arrayto::LTSV); // =\u003e SMB\\Arrayto\\Ltsv\n  // $ltsv == Arrayto\\Ltsv::factory();\n\n  $xml = Arrayto::factory(Arrayto::XML);   // =\u003e SMB\\Arrayto\\Xml\n  // $xml == Arrayto\\Xml::factory();\n\n  $json = Arrayto::factory(Arrayto::JSON); // =\u003e SMB\\Arrayto\\Json\n  // $json == Arrayto\\Json::factory();\n```\n- ``` Arrayto\\Plugins\\XXX\\XXX ```\n```php\n  \u003c?php\n  use SMB\\Arrayto;\n\n  $csvDownloader = new Arrayto\\Plugins\\Csv\\Downloader();\n  // $csvDownloader == Arrayto\\Csv::factory()-\u003egetDownloader();\n  $csvOutputter = new Arrayto\\Plugins\\Csv\\Outputter();\n  // $csvOutputter == Arrayto\\Csv::factory()-\u003egetOutputter();\n  $csvWriter = new Arrayto\\Plugins\\Csv\\Writer();\n  // $csvWriter == Arrayto\\Csv::factory()-\u003egetWriter();\n\n  $tsvDownloader = new Arrayto\\Plugins\\Tsv\\Downloader();\n  // $tsvDownloader == Arrayto\\Tsv::factory()-\u003egetDownloader();\n  $tsvOutputter = new Arrayto\\Plugins\\Tsv\\Outputter();\n  // $tsvOutputter == Arrayto\\Tsv::factory()-\u003egetOutputter();\n  $tsvWriter = new Arrayto\\Plugins\\Tsv\\Writer();\n  // $tsvWriter == Arrayto\\Tsv::factory()-\u003egetWriter();\n\n  $ltsvDownloader = new Arrayto\\Plugins\\Ltsv\\Downloader();\n  // $ltsvDownloader == Arrayto\\Ltsv::factory()-\u003egetDownloader();\n  $ltsvWriter = new Arrayto\\Plugins\\Ltsv\\Writer();\n  // $ltsvWriter == Arrayto\\Ltsv::factory()-\u003egetWriter();\n\n  $xmlDownloader = new Arrayto\\Plugins\\Xml\\Downloader();\n  // $xmlDownloader == Arrayto\\Xml::factory()-\u003egetDownloader();\n  $xmlWriter = new Arrayto\\Plugins\\Xml\\Writer();\n  // $xmlWriter == Arrayto\\Xml::factory()-\u003egetWriter();\n\n  $jsonDownloader = new Arrayto\\Plugins\\Json\\Downloader();\n  // $jsonDownloader == Arrayto\\Json::factory()-\u003egetDownloader();\n  $jsonOutputter = new Arrayto\\Plugins\\Json\\Outputter();\n  // $jsonOutputter == Arrayto\\Json::factory()-\u003egetOutputter();\n  $jsonWriter = new Arrayto\\Plugins\\Json\\Writer();\n  // $jsonWriter == Arrayto\\Json::factory()-\u003egetWriter();\n```\n\n## Testing\n\n```\nvendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshimabox%2Fsmbarrayto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshimabox%2Fsmbarrayto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshimabox%2Fsmbarrayto/lists"}