PHP code example of petrobolos / fixed-array-functions
1. Go to this page and download the library: Download petrobolos/fixed-array-functions 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/ */
petrobolos / fixed-array-functions example snippets
use Petrobolos\FixedArray\FixedArrayable;
// You can start by either instantiating a new instance of FixedArrayable, or by calling its helper method:
// The array provided will be converted internally into an SplFixedArray.
$array = new FixedArrayable([1, 2, 3]);
// You can also use the helper function to do the same thing!
$array = fixedArray([1, 2, 3]);
// Lastly, you can use specific methods to begin building your interface logic:
// The same will happen with this collection.
$array = FixedArrayable::fromCollection(collect([1, 2, 3]);
// From here, you can chain different methods, just like you would a collection.
$result = $array
->addFrom([4, 5, 6])
->resize(20)
->filter(fn ($value) => $value % 2 === 0))
->map(fn ($value) => $value * 2))
->get();
// The result will be a SplFixedArray containing [2, 4, 6] but still with 20 indices.
use Petrobolos\FixedArray;
// Create a fixed array using the create method.
$arr = FixedArray::create();
// Easily push or pop items to and from arrays without worrying about indices.
FixedArray::push('apple', $arr);
// Easily and efficiently merge fixed arrays, regular arrays, and even Illuminate collections.
$everything = FixedArray::merge(
$arr,
['a', 'regular', 'array'],
collect(['and', 'an', 'illuminate', 'collection']),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.