PHP code example of tekord / php-option

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

    

tekord / php-option example snippets


$o = Option::some(200);
$value = $o->unwrap(); // -> 200

$o = Option::none();
$value = $o->unwrap(); // -> ERROR

$o = Option::none();
$value = $o->unwrapOrDefault(50); // -> 50

$o = Option::none();
$value = $o->unwrapOrNull(); // -> null

$o = Option::some("Hello");
$o->isSome(); // true
$o->isNone(); // false

$o = Option::none();
$o->isSome(); // false
$o->isNone(); // true
bash
composer