PHP code example of rinimisini / php-utilities

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

    

rinimisini / php-utilities example snippets


$set = new Set();

$set->add(1);
$set->add(2);
$set->add(3);

if ($set->has(2)) {
echo "Set contains 2";
}

$set->delete(2);

$set->clear();

echo $set->size();  // Outputs the number of elements in the set

$set1 = new Set();
$set1->add(1)->add(2);

$set2 = new Set();
$set2->add(2)->add(3);

$unionSet = $set1->union($set2);  // $unionSet contains [1, 2, 3]

$set1 = new Set();
$set1->add(1)->add(2);

$set2 = new Set();
$set2->add(2)->add(3);

$intersectionSet = $set1->intersection($set2);  // $intersectionSet contains [2]

$set1 = new Set();
$set1->add(1)->add(2);

$set2 = new Set();
$set2->add(2)->add(3);

$differenceSet = $set1->difference($set2);  // $differenceSet contains [1]

foreach ($set as $item) {
echo $item;
}

$set = new Set();
$set->add(1)->add(2);

$serialized = serialize($set);
$unserializedSet = unserialize($serialized);

$map = new Map();

$map->set('name', 'Alice');
$map->set('age', 30);

echo $map->get('name');  // Outputs: Alice

if ($map->has('age')) {
echo "Age is set in the map.";
}

$map->delete('age');  // Removes the entry with key 'age'

foreach ($map as [$key, $value]) {
echo "Key: $key, Value: $value\n";
}

$map->forEach(function ($value, $key) {
echo "Key: $key, Value: $value\n";
});

$keys = $map->keys();     // Returns an array of keys
$values = $map->values(); // Returns an array of values

$map->clear();

$weakSet = new WeakSet();

$obj = new stdClass();
$weakSet->add($obj);

if ($weakSet->has($obj)) {
echo "Object exists in the WeakSet";
}

$weakSet->delete($obj);

$weakSet->clear();

foreach ($weakSet as $object) {
echo get_class($object);
}
bash
composer