douke1891 2017-01-04 14:45
浏览 28

PHP设置函数[重复]

This question already has an answer here:

I need to set up a function which will convert random number between 1 and 7 into days of a week for example if the random numbers appears to be "1" it should display "Monday" and same goes for "2" which will display "Tuesday" etc. Does anyone here know the simple way of doing it ? Also later on in the second task i'll have to make all the days of the week display from Monday until a random day of the week(1-7) for example "Friday". Im pretty new to PHP and this got me so confused.

</div>
  • 写回答

2条回答 默认 最新

  • douzhun5971 2017-01-04 14:50
    关注

    Custom function could be like:

    function convertWeekday($num) {
       switch ($num) {
          case 1: $result = 'Monday'; break;
          case 2: $result = 'Tuesday'; break;
          case 3: $result = 'Wednesday'; break;
          case 4: $result = 'Thursday'; break;
          case 5: $result = 'Friday'; break;
          case 6: $result = 'Saturday'; break;
          case 7: $result = 'Sunday'; break;
       }
       return $result;
    }
    

    But you should better make use of the PHP date() function.

    http://php.net/manual/en/function.date.php

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度