kjohnson/format-object-list

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

0.1.0 2021-01-18 22:22 UTC

This package is auto-updated.

Last update: 2024-10-25 23:38:46 UTC


README

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

Installation

composer require kjohnson/format-object-list

Usage

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