Home  >  Article  >  php教程  >  PHP天干地支、生肖的生成

PHP天干地支、生肖的生成

PHP中文网
PHP中文网Original
2016-05-25 16:59:402127browse

PHP,天干地支、生肖生成

<?php
/*天干地支算法:
一.公元后的:
天干:甲4 乙5 丙6 丁7 戊8 己9 庚0 辛1 壬2 癸3 
如1894年末尾一个数是4就甲年,依此类推

地支:子4 丑5 寅6 卯7 辰8 巳9 午10 未11 申0 酉1 戌2 亥3  
换算:1894除以12,余数是几,就在地支中找几.


二.公元前的:
天干:甲7 乙6 丙5 丁4 戊3 己2 庚1 辛0 壬9 癸8 
如公元前7年就是甲年依此类推

地支:子-9 丑-8 寅-7 卯-6 辰-5 巳-4 午-3 未-2 申-1 酉0 戌-11 亥-10
换算:如公元前221年,-221除以12,余数是几,就在地支中找几

*/
   	$TGDZ = array (array (&#39;甲&#39;, &#39;乙&#39;, &#39;丙&#39;, &#39;丁&#39;, &#39;戊&#39;, &#39;己&#39;, &#39;庚&#39;, &#39;辛&#39;, &#39;壬&#39;, &#39;癸&#39; ), 
   	array (&#39;子&#39;, &#39;丑&#39;, &#39;寅&#39;, &#39;卯&#39;, &#39;辰&#39;, &#39;巳&#39;, &#39;午&#39;, &#39;未&#39;, &#39;申&#39;, &#39;酉&#39;, &#39;戌&#39;, &#39;亥&#39; ) );
   	$Year = 2014;
   	$Year_JiSuan = $Year - 1900 + 36;
   	$TianGanDiZhi = $TGDZ[0][$Year_JiSuan % 10] . $TGDZ[1][$Year_JiSuan % 12];
   	echo $Year."年为农历[".$TianGanDiZhi."]年";
?>

2. 天干地支算法2

<?php
/*天干地支算法版本2:*/
   	$TGDZ = array (array (&#39;庚&#39;, &#39;辛&#39;, &#39;壬&#39;, &#39;癸&#39; ,&#39;甲&#39;, &#39;乙&#39;, &#39;丙&#39;, &#39;丁&#39;, &#39;戊&#39;, &#39;己&#39;), 
   array ( &#39;申&#39;, &#39;酉&#39;, &#39;戌&#39;, &#39;亥&#39;, &#39;子&#39;, &#39;丑&#39;, &#39;寅&#39;, &#39;卯&#39;, &#39;辰&#39;, &#39;巳&#39;, &#39;午&#39;, &#39;未&#39;) );
   	for ($Year = 1900; $Year <= 2099; $Year++) 
   	{ 
	   	$TianGanDiZhi = $TGDZ[0][$Year % 10] . $TGDZ[1][$Year % 12];
	   	echo $Year . "年为农历[" . $TianGanDiZhi . "]年<br>";
   	}
?>

3. 生肖算法1

/*生肖算法版本1:*/
if($_POST[&#39;year&#39;]){
$y = $_POST[&#39;year&#39;];
$sxdict = array(&#39;猴&#39;, &#39;鸡&#39;, &#39;狗&#39;, &#39;猪&#39;,&#39;鼠&#39;, &#39;牛&#39;, &#39;虎&#39;, &#39;兔&#39;, &#39;龙&#39;, &#39;蛇&#39;, &#39;马&#39;, &#39;羊&#39;); 
$result[&#39;sx&#39;] = $sxdict[$y%12]; 
var_dump($result[&#39;sx&#39;]);
}
?>

    4. 生肖算法2 (按照正常顺序)

<?php
/*生肖算法版本2:*/
if($_POST[&#39;year&#39;]){
$y = $_POST[&#39;year&#39;];
$sxdict = array(&#39;鼠&#39;, &#39;牛&#39;, &#39;虎&#39;, &#39;兔&#39;, &#39;龙&#39;, &#39;蛇&#39;, &#39;马&#39;, &#39;羊&#39;, &#39;猴&#39;, &#39;鸡&#39;, &#39;狗&#39;, &#39;猪&#39;); 
$result[&#39;sx&#39;] = $sxdict[(($y-4)%12)]; 
var_dump($result[&#39;sx&#39;]);
}
?>


以上就是PHP天干地支、生肖的生成的内容,更多相关内容请关注PHP中文网(www.php.cn)!

   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn