国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php實現每天自動變換隨機問候語的方法

2024-05-04 23:35:04
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php實現每天自動變換隨機問候語的方法,涉及時間與數組的相關操作技巧,需要的朋友可以參考下

本文實例講述了php實現每天自動變換隨機問候語的方法。分享給大家供大家參考。具體分析如下:

這里預先定義一個php數組,里面存放一些隨機問候語,調用的時候指定是按照天,月還是年來自動更換問候語,如果選擇月,則會每月更換一條問候語顯示,不用每個月手動更換了,并且這段php代碼比使用JS實現對搜索引擎友好

 

 
  1. function RandomQuoteByInterval($TimeBase$QuotesArray){ 
  2. // Make sure it is a integer 
  3. $TimeBase = intval($TimeBase); 
  4. // How many items are in the array? 
  5. $ItemCount = count($QuotesArray); 
  6. // By using the modulus operator we get a pseudo 
  7. // random index position that is between zero and the 
  8. // maximal value (ItemCount) 
  9. $RandomIndexPos = ($TimeBase % $ItemCount); 
  10. // Now return the random array element 
  11. return $QuotesArray[$RandomIndexPos]; 
  12. /* 
  13. ** --> See the example section below for a 
  14. ** detailed instruction. 
  15. */ 

使用范例:

 

 
  1. // Use the day of the year to get a daily changing 
  2. // quote changing (z = 0 till 365) 
  3. $DayOfTheYear = date('z'); 
  4. // You could also use: 
  5. // --> date('m'); // Quote changes every month 
  6. // --> date('h'); // Quote changes every hour 
  7. // --> date('i'); // Quote changes every minute 
  8. // Example array with some random quotes 
  9. $RandomQuotes = array
  10. 'No animals were harmed in the making of this snippet.'
  11. 'Nice snippets'
  12. 'The modulus operator rocks!'
  13. 'PHP is cool.' 
  14. ); 
  15. print RandomQuoteByInterval($DayOfTheYear$RandomQuotes); 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安陆市| 龙里县| 惠安县| 潞西市| 武安市| 兴海县| 手游| 包头市| 油尖旺区| 舞阳县| 安宁市| 昌宁县| 新营市| 巴楚县| 周至县| 弋阳县| 台北县| 崇阳县| 贡觉县| 宿州市| 墨竹工卡县| 车险| 常州市| 新兴县| 永和县| 醴陵市| 甘孜| 汤原县| 六安市| 琼结县| 九龙县| 开江县| 武平县| 南开区| 澜沧| 乌拉特后旗| 呼伦贝尔市| 应城市| 淳安县| 瓦房店市| 怀安县|