hrevert/day-of-week
Composer 安装命令:
composer require hrevert/day-of-week
包简介
Day of week library
README 文档
README
Day of week library
Usage
Please read the docs of php-enum first.
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)
Since Hrevert\Day\DayCollection is just an extension of Doctrine\Common\Collections\ArrayCollection, it should not be so difficult.
Using in <select> element
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']);
统计信息
- 总下载量: 43
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-24