PHP code example of marvin255 / optional

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

    

marvin255 / optional example snippets


use Marvin255\Optional\Optional;

$optional = Optional::of($input);
if ($optional->isPresent()) {
    $value = $optional->get();
    // do something
}

use Marvin255\Optional\Optional;

Optional::of($input)->ifPresent(function ($item): void {/* do something */});