Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to calculate the Chinese Zodiac, or must I use a lookup table?

I'm building an application that will tell your Chinese sign. I looked around but only found charts (from 1900 to 2020), and no logic to create something more dynamic.

Is there no logic for determining a Chinese zodiac?

like image 714
Michel Ayres Avatar asked May 01 '12 17:05

Michel Ayres


1 Answers

Use this to calculate the year.

<?php

$year = 2013;
    switch (($year - 4) % 12) {
        case  0: $zodiac = 'Rat';       break;
        case  1: $zodiac = 'Ox';            break;
        case  2: $zodiac = 'Tiger';     break;
        case  3: $zodiac = 'Rabbit';    break;
        case  4: $zodiac = 'Dragon';    break;
        case  5: $zodiac = 'Snake';     break;
        case  6: $zodiac = 'Horse';     break;
        case  7: $zodiac = 'Goat';  break;
        case  8: $zodiac = 'Monkey';    break;
        case  9: $zodiac = 'Rooster';   break;
        case 10: $zodiac = 'Dog';   break;
        case 11: $zodiac = 'Pig';   break;
    }
    echo "{$year} is the year of the {$zodiac}.<br />";


?>
like image 64
user1829823 Avatar answered Nov 21 '22 20:11

user1829823