PHP code example of mgocobachi / collection

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

    

mgocobachi / collection example snippets



echo collection([1, 2, 3])->first();



$users = [
  [
    'name'  => 'John',
    'email' => '[email protected]',
  ],
  [
    'name'  => 'Clark',
    'email' => null,
  ],
  [
    'name'  => 'Jennifer',
    'email' => '[email protected]',
  ],
  [
    'name'  => 'Jimmy',
    'email' => null,
  ],
];

$users = collection($users)->filter(function ($user) {
  return !empty($user);
})->all();

var_dump($users);