国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁城县| 沙田区| 察哈| 舒兰市| 株洲市| 朝阳市| 安丘市| 彰武县| 海门市| 小金县| 鄂托克旗| 万州区| 富民县| 浦东新区| 南部县| 阿克| 上杭县| 夏津县| 长泰县| 缙云县| 太原市| 儋州市| 凤山市| 邵阳市| 隆德县| 望奎县| 巢湖市| 错那县| 娄烦县| 桓仁| 嘉义县| 马龙县| 屏南县| 安图县| 太仆寺旗| 南康市| 报价| 兴文县| 汤阴县| 田东县| 长治市|