1. Go to this page and download the library: Download twelver313/rich-array 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/ */
twelver313 / rich-array example snippets
use Twelver313\RichArray\RichArray;
// Initialize a RichArray
$richArray = new RichArray([1, 2, 3]);
// Access elements like an array
echo $richArray[0]; // Output: 1
// Use forEach (just like JavaScript)
$richArray->forEach(function ($value, $key) {
echo "Index: $key, Value: $value\n";
});
// Find an element (returns the first match)
$found = $richArray->find(function ($value) {
return $value === 2;
});
echo $found; // Output: 2
// Filter elements (returns a new RichArray)
$filtered = $richArray->filter(function ($value) {
return $value > 1;
});
$filtered->forEach(function ($value) {
echo $value . ' '; // Output: 2 3
});
// The original array remains unchanged
print_r($richArray); // Output: [1, 2, 3]
$richArray->forEach(function ($value, $key) {
// Custom logic for each element
});