philsown/boolify

A PHP Library to make something a boolean.

dev-master 2024-04-26 16:06 UTC

This package is not auto-updated.

Last update: 2024-09-18 17:12:17 UTC


README

A PHP Library to make something that's kinda true or false into a genuine boolean.

This will take a variety of values and return either true or false.

Usage

<?php

use Phdc\Boolify\Boolify;

// $someValue has been set previously
$bool = Boolify::cast($someValue);

// $bool is now a boolean

True Values

  • true
  • "True"
  • "true"
  • 1
  • "1"
  • "Yes"
  • "yes"
  • "Y"
  • "y"
  • An integer greater than 0
  • A non-empty array
  • A non-empty object

False Values

  • false
  • "False"
  • "false"
  • "F"
  • "f"
  • 0
  • "0"
  • "No"
  • "no"
  • "N"
  • "n"
  • Any integer less than 1
  • An empty array
  • An empty object
  • Null