PHP code example of benammi / php-arrays-all-in-one

1. Go to this page and download the library: Download benammi/php-arrays-all-in-one 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/ */

    

benammi / php-arrays-all-in-one example snippets


use Benammi\ArrayAIO\ArrayAIO;
use Benammi\ArrayAIO\Collection;

$users = collect([
    ['name' => 'Hamza', 'active' => true, 'score' => 20],
    ['name' => 'Sara', 'active' => false, 'score' => 35],
    ['name' => 'Omar', 'active' => true, 'score' => 15],
]);

$names = $users
    ->where('active', true)
    ->sortBy('score')
    ->pluck('name')
    ->values()
    ->all();
// ['Omar', 'Hamza']

collect([1, 2, 3, 4])
    ->filter(fn ($n) => $n % 2 === 0)
    ->map(fn ($n) => $n * 10)
    ->sum();
// 60

ArrayAIO::stringToArray('hello world', ' ');
// ['hello', 'world']

ArrayAIO::merge([1, 2], [3], ['r']);
// [1, 2, 3, 'r']

ArrayAIO::getDot(['user' => ['name' => 'Hamza']], 'user.name');
// 'Hamza'

ArrayAIO::pluck([
    ['id' => 1, 'name' => 'A'],
    ['id' => 2, 'name' => 'B'],
], 'name', 'id');
// [1 => 'A', 2 => 'B']