Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kjohnson/format-object-list

Formats an associative array into a JS parsable array of objects.
https://github.com/kjohnson/format-object-list

Last synced: 20 days ago
JSON representation

Formats an associative array into a JS parsable array of objects.

Awesome Lists containing this project

README

        

# Format Object List

Formats an associative array into a JS parsable array of label/value objects.

## Installation

`composer require kjohnson/format-object-list`
## Usage

```php
$data = [ 'foo' => 'bar' ];
$formatter = FormatObjectList\Factory::fromKeyValue( $data );
$list = $formatter->format();
// [ [ 'label' => 'bar', 'value' => 'foo' ] ]
```

```php
$data = [ 'foo' => 'bar' ];
$formatter = FormatObjectList\Factory::fromValueKey( $data );
$list = $formatter->format();
// [ [ 'label' => 'foo', 'value' => 'bar' ] ]
```