PHP code example of chevere / data-structure

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

    

chevere / data-structure example snippets


use Chevere\DataStructure\Map;

$map = new Map(foo: $foo, bar: $bar);

$map = $map
    ->withPut(
        foo: $foo,
        bar: $bar
    );

$map->count();
// 2

$map->keys();
// ['foo', 'bar']

$map->has('foo'); // true
$map->has('notFound'); // false

$map->assertHas('foo');
$map->assertHas('notFound');

$foo = $map->get('foo');

$foo = $map->getOrDefault('foo', null);
// Return null if not found

use Chevere\DataStructure\Vector;

$vector = new Vector($value1, $value2,);

$vector->count();
// 2

$map->keys();
// [0, 1]

$with = $vector->withPush($value,);

$with = $vector->withSet(0, $value);

$with = $vector->withUnshift($value,);

$with = $vector->withInsert($pos, ...$values);

$with = $vector->withRemove($pos,);

$vector->has($value); // true
$vector->has($notFound); // false

$vector->assertHas($value);

$value = $vector->get($pos);

$pos = $vector->find($value);

$vector->contains($value); // bool