PHP code example of hrevert / day-of-week

1. Go to this page and download the library: Download hrevert/day-of-week 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/ */

    

hrevert / day-of-week example snippets


use Hrevert\Day\Day;

/** @var Day */
$day = Day::get(Day::MONDAY);
// or $day = Day::MONDAY();
// or $day = Day::getByName('MONDAY');
// or $day = Day::getByOrdinal(1);  i.e. find by ISO-8601 numeric representation of day

/** @var Day */
$today = Day::getToday();

use Hrevert\Day\Day;
use Hrevert\Day\DayCollection;

$days = new DayCollection([Day::SUNDAY(), Day::MONDAY()]);

var_dump($days->contains(Day::SUNDAY())); // bool(true)
var_dump($days->contains(Day::MONDAY())); // bool(true)

$days->remove(Day::MONDAY());
var_dump($days->contains(Day::MONDAY())); // bool(false)

$days->add(Day::MONDAY());
var_dump($days->contains(Day::MONDAY())); // bool(true)


use Hrevert\Day\Day;

echo '<select name="day">';
foreach (Day::getOptions() as $iso => $display) {
    echo '<option value="' . $iso . '">' . $display . '</option>';
}
echo '</select>';


// on form submit
/** @var Hrevert\Day\Day */
$day = Hrevert\Day\Day::get((int) $_POST['day']);