PHPackages                             kfriars/php-array-to-file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kfriars/php-array-to-file

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kfriars/php-array-to-file
=========================

Convert a php array into a .php file that can be included

1.1.2(5y ago)44.7k21MITPHPPHP ^7.2CI failing

Since Aug 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kfriars/php-array-to-file)[ Packagist](https://packagist.org/packages/kfriars/php-array-to-file)[ Docs](https://github.com/spatie/php-array-to-file)[ RSS](/packages/kfriars-php-array-to-file/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (4)Versions (5)Used By (1)

Convert a php array into an includeable php file
================================================

[](#convert-a-php-array-into-an-includeable-php-file)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8de6d73288eba9d45ec5d162c2894b94404a90e25919595c42efb034788e6fd7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6672696172732f7068702d61727261792d746f2d66696c652e7376673f636f6c6f723d253233346363643938267374796c653d666c61742d737175617265)](https://packagist.org/packages/kfriars/php-array-to-file)[![Total Downloads](https://camo.githubusercontent.com/4aa1b62aa4bb52f7dcae705c36d9e29dc41633be589683edfd91eaa8c46dc166/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6672696172732f7068702d61727261792d746f2d66696c652e7376673f636f6c6f723d253233346363643938267374796c653d666c61742d737175617265)](https://packagist.org/packages/kfriars/php-array-to-file)[![GitHub Workflow Status](https://camo.githubusercontent.com/5d564f78f7049bac28db6a45faeb1917b22577f9d57665957b5ec68d249894e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6b6672696172732f7068702d61727261792d746f2d66696c652f54657374733f636f6c6f723d253233346363643938266c6162656c3d5465737473266c6f676f3d676974687562266c6f676f436f6c6f723d253233666666)](https://github.com/kfriars/php-array-to-file/actions?query=workflow%3Arun-tests+branch%3Amaster)[![Code Climate coverage](https://camo.githubusercontent.com/462e0ddd38c8e068d24a20f8ba6216c414d90e8a0bade596c1ef8b08bd8ae210/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6b6672696172732f7068702d61727261792d746f2d66696c653f636f6c6f723d253233346363643938266c6162656c3d74657374253230636f766572616765266c6f676f3d636f64652d636c696d617465266c6f676f436f6c6f723d253233666666)](https://codeclimate.com/github/kfriars/php-array-to-file/test_coverage)[![Code Climate maintainability](https://camo.githubusercontent.com/254c623e363ba5548cc757f6000a15f0cb54d6ea8f2036d7cce218251c747d3c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f6b6672696172732f7068702d61727261792d746f2d66696c653f636f6c6f723d253233346363643938266c6162656c3d6d61696e7461696e61626c696c697479266c6f676f3d636f64652d636c696d617465266c6f676f436f6c6f723d253233666666)](https://codeclimate.com/github/kfriars/php-array-to-file/maintainability)

The purpose of this package is to print an array to a file in a reader-friendly format, that can later be included as php. The package supports deeply nested arrays, with numeric, string, boolean and object values.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kfriars/php-array-to-file
```

Usage
-----

[](#usage)

You can use the static method `toFile(...)` on `Kfriars\ArrayToFile\ArrayWriter` for convenient use, or you can inject the `Kfriars\ArrayToFile\ArrayToFile` class as a dependency, and use `write(...)`.

An example of use:

```
ArrayWriter::toFile([1, 2, 3], '/absolute/path/to/file.php');
```

Would create `/absolute/path/to/file.php` with the contents:

```
