PHP code example of ngtfkx / laradeck-collection-macros

1. Go to this page and download the library: Download ngtfkx/laradeck-collection-macros 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/ */

    

ngtfkx / laradeck-collection-macros example snippets

 php
$arr = [
    ['id' => '10', 'name' => 'First', ],
    ['id' => '20', 'name' => 'Second', ],
    ['id' => '30', 'name' => 'Third', ],
];
$collect = new Collection($arr);
$keyValueArray = $collect->forSelect('name')
//[
//    '10' => 'First',
//    '20' => 'Second',
//    '30' => 'Third',
//]
 php
$collect = new Collection([1, 2, 3]);
$randoms = $collect->randomSafe(10);
echo sizeof($randoms); // 3