PHP code example of bradietilley / carbon-zodiac

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

    

bradietilley / carbon-zodiac example snippets


\BradieTilley\Zodiac\Zodiac::boot();

use Carbon\Carbon;
use BradieTilley\Zodiac\Zodiac;
use BradieTilley\Zodiac\Sign;
use BradieTilley\Zodiac\Element;

/** Set up some dummy dates */
$date1 = Carbon::parse('1970-02-05');
$date2 = Carbon::parse('1970-02-06');

/** Convert a date to a zodiac year */
$date1->zodiacYear(); // 1969
$date2->zodiacYear(); // 1970

/** Convert a date to a zodiac sign */
$date1->zodiacSign(); // Sign::ROOSTER
$date2->zodiacSign(); // Sign::DOG

/** Convert a date to a zodiac element */
$date1->zodiacElement(); // Element::EARTH
$date2->zodiacElement(); // Element::METAL

use Carbon\Carbon;
use BradieTilley\Zodiac\Zodiac;
use BradieTilley\Zodiac\Sign;
use BradieTilley\Zodiac\Element;

/** Set up some dummy dates */
$date1 = Carbon::parse('1970-02-05');
$date2 = Carbon::parse('1970-02-06');

/** Convert a date to a zodiac year */
Zodiac::yearFromDate($date1); // Year<1969>
Zodiac::yearFromDate($date2); // Year<1970>

/** Convert a date to a zodiac sign */
Zodiac::signFromDate($date1); // Sign::ROOSTER
Zodiac::signFromDate($date2); // Sign::DOG

/** Convert a date to a zodiac element */
Zodiac::elementFromDate($date1); // Element::EARTH
Zodiac::elementFromDate($date2); // Element::METAL

use Carbon\Carbon;
use BradieTilley\Zodiac\Zodiac;
use BradieTilley\Zodiac\Sign;
use BradieTilley\Zodiac\Element;

/** Set up some dummy dates */
$date1 = Carbon::parse('1970-02-05');
$date2 = Carbon::parse('1970-02-06');

/** Convert a date to a zodiac year */
Year::fromDate($date1); // Year<1969>
Year::fromDate($date2); // Year<1970>

/** Convert a date to a zodiac sign */
Sign::fromDate($date1); // Sign::ROOSTER
Sign::fromDate($date2); // Sign::DOG

/** Convert a date to a zodiac element */
Element::fromDate($date1); // Element::EARTH
Element::fromDate($date2); // Element::METAL

$rooster = Sign::fromDate(Carbon::parse('1970-02-05')):
$dog = Sign::fromDate(Carbon::parse('1970-02-06')):

$rooster->yinYang();      // Yin
$rooster->direction();    // West
$rooster->season();       // Mid-Autumn
$rooster->fixedElement(); // Metal
$rooster->trine();        // 2

$dog->yinYang();          // Yang
$dog->direction();        // West
$dog->season();           // Late Autumn
$dog->fixedElement();     // Earth
$dog->trine();            // 3

$year = Year::fromDate(Carbon::parse('2024-02-10'));
$year = Year::fromYear(2024); // same as above

$year->prev(); // Year<2023>
$year->next(); // Year<2025>

$year->sign(); // Sign::DRAGON
$year->element(); // Element::WOOD

json_encode($year->toArray());
/**
 * {
 *     "year": 2024,
 *     "start": "2024-02-10",
 *     "end": "2025-01-28"
 * }
 */

$sign = Sign::fromDate(Carbon::parse('2024-02-10'));
$sign = Sign::fromYear(2024); // same as above

$sign; // Sign::DRAGON

$sign->value; // dragon
$sign->label(); // Dragon

json_encode($sign->toArray());
/**
 * {
 *     "value": "dragon",
 *     "label": "Dragon",
 *     "data": {
 *         "yin_yang": "Yang",
 *         "direction": "East",
 *         "season": "Late Spring",
 *         "fixed_element": {
 *             "value": "earth",
 *             "label": "Earth"
 *         },
 *         "trine": 1
 *     }
 * }
 */

$element = Element::fromDate(Carbon::parse('2024-02-10'));
$element = Element::fromYear(2024); // same as above

$element; // Element::WOOD

$element->value; // wood
$element->label(); // Wood

json_encode($element->toArray());
/**
 * {
 *     "value": "wood",
 *     "label": "Wood",
 * }
 */