Skip to content

amostajo/php-json-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONArray (PHP class)

Latest Stable Version Total Downloads License

Simple class that extends the capabilities of the basic php array by adding json casting and file handling (read and write).

Quick start

  • Clone or download the latest release.
  • Via composer:
composer require amostajo/php-json-array

Usage

Creating an array:

$array = new JSONArray();

Add items as you normally would do using arrays:

$array[] = 'example';

$array['ID'] = 123;
$array['person'] = ['name' => 'John', 'lastname' => 'Doe'];

Casting:

// To JSON
echo $array->toJson();

// To string (casts to JSON at the end)
echo (string)$array;

Write to file:

// Writes array as json string into filename.
$array->write($filename);

Read from file:

// Reads from filename.
$array->read($filename);

// Use loaded array
echo $array[$key];

Coding Guidelines

The coding is PSR-2.

License

JSONArray is free software distributed under the terms of the MIT license.

About

JSON Array is a useful type of array that easily casts to JSON, writes and reads .json files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages