PHP code example of phpfluent / arraystorage

1. Go to this page and download the library: Download phpfluent/arraystorage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpfluent / arraystorage example snippets


use PHPFluent\ArrayStorage\Storage;

$storage = new Storage();
$storage->users; // This is a collection

$storage = new Storage();
$storage->users->insert(['name' => 'Henrique Moody']);

use PHPFluent\ArrayStorage\Record;

$storage = new Storage();
$record = new Record();
$record->name = 'Henrique Moody';

$storage->users->insert($record);

$storage = new Storage();

$record = $storage->users->record(); // You also can provide default data, like an array or stdClass
$record->name = 'Henrique Moody';

$storage->users->insert($record);

$storage = new Storage();
$storage->users->delete(['name' => 'Henrique Moody']);

$storage = new Storage();
$storage->users->delete();

$storage->users->findAll(['status !=' => false]); // Return an Collection object with the partial result (if any)

$storage->users->find(['priority >=' => 4]); // Return an Record object with the first matched result (if any) or NULL

$criteria = $storage->users->criteria();
$criteria->foo->equalTo(2)
         ->bar->in([1, 2, 3])
         ->baz->regex('/^[0-9]{3}$/')
         ->qux->like('This _s spart%')
         ->quux->iLike('tHiS _S sPaRt%')
         ->corge->between(array(1, 42))
         ->grault->lessThan(1000)
         ->garply->greaterThan(0)
         ->waldo->notEqualTo(false)
         ->fred->greaterThanOrEqualTo(13);

$storage->users->find($criteria);

use PHPFluent\ArrayStorage\Converter;

$converter = new Converter\Arr();
$converter->convert($storage->collectionName); // Returns an array with the records as array too

$converter = new Converter\Arr(false);
$converter->convert($storage->collectionName); // Returns an array of Record objects

$converter = new Converter\Json();
$converter->convert($storage->collectionName); // Returns an string with the JSON

$converter = new Converter\Json(JSON_NUMERIC_CHECK);
$converter->convert($storage->collectionName); // Returns the JSON but encodes numeric strings as numbers

$converter = new Converter\Xml();
$converter->convert($storage->collectionName); // Returns an string with the XML