PHP code example of werx / collections

1. Go to this page and download the library: Download werx/collections 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/ */

    

werx / collections example snippets


$foo = new \werx\Collections\Collection;

class Foo extends \werx\Collections\Collection
{

}

$foo = new Foo();

$foo = new new \werx\Collections\Collection(['foo' => 'Foo', 'bar' => 'bar']);

$foo = new Foo();
$foo->set(['foo' => 'Foo', 'bar' => 'bar']);

var_dump($foo->count());
# OR
var_dump(count($foo)); // The Collection class implements the Countable() interface.
// 2

var_dump($foo->has('foo'));
// true
 php
var_dump($foo->has('x'));
// false
 php
var_dump($foo->get('foo'));
// Foo
 php
var_dump($foo->get('x'));
// null
 php
var_dump($foo->get('x', 'no'));
// no
 php
$foo->set('name', 'Josh');
 php
$foo->add('Josh');
 php
$foo->add(['name' => 'Josh', 'location' => 'Arkansas']);
 php
$foo->remove('name');
 php
$foo->all();
 php
$foo->toArray();
 php
var_dump($foo->toJson());
// {"foo":"Foo","bar":"Bar"}
 php
var_dump((string) $foo);
// {"foo":"Foo","bar":"Bar"}
 php
$foo->clear();