mirror of
https://github.com/Estom/notes.git
synced 2026-02-02 18:20:20 +08:00
123 lines
2.2 KiB
Markdown
123 lines
2.2 KiB
Markdown
\>多维数组的建立
|
||
|
||
\>\>对于多维数组来说,同样需要多级索引来定位元素
|
||
|
||
**[html]** [view plain](http://blog.csdn.net/estom_yin/article/details/51920304)
|
||
[copy](http://blog.csdn.net/estom_yin/article/details/51920304)
|
||
|
||
1. **\<body\>**
|
||
|
||
2.
|
||
|
||
3. **\<?php**
|
||
|
||
4. \$cars = array
|
||
|
||
5. (
|
||
|
||
6. array("Volvo",33,20),
|
||
|
||
7. array("BMW",17,15),
|
||
|
||
8. array("Saab",5,2),
|
||
|
||
9. array("Land Rover",15,11)
|
||
|
||
10. );
|
||
|
||
11.
|
||
|
||
12. for (\$row = 0; \$row **\<** **4**; \$row++) {
|
||
|
||
13. echo "**\<p\>\<b\>**行数 \$row**\</b\>\</p\>**";
|
||
|
||
14. echo "**\<ul\>**";
|
||
|
||
15. for (\$col = 0; \$col **\<** **3**; \$col++) {
|
||
|
||
16. echo "**\<li\>**".\$cars[\$row][\$col]."**\</li\>**";
|
||
|
||
17. }
|
||
|
||
18. echo "**\</ul\>**";
|
||
|
||
19. }
|
||
|
||
20. **?\>**
|
||
|
||
21.
|
||
|
||
22. **\</body\>**
|
||
|
||
//这些代码也说明了一个问题,使用php可以直接输出html格式并显示
|
||
|
||
\>日期
|
||
|
||
PHP中Date(format, timestamp)
|
||
|
||
timestamp 规定时间戳,默认是当前时间
|
||
|
||
format 规定时间格式
|
||
|
||
d月中某天
|
||
|
||
m某月
|
||
|
||
y某年
|
||
|
||
l周里某天
|
||
|
||
h带有首位零的12小时格式
|
||
|
||
i带有首位零的分钟格式
|
||
|
||
s带有首位零的秒
|
||
|
||
a小写的五千后午后
|
||
|
||
date_default_timezone_set("Asia/Shanghai")//修改时区
|
||
|
||
mktime(hour, minute, second, month, day, year)//设定时间戳
|
||
|
||
strtotime(变化时间, now开始时间)//创建日期时间
|
||
|
||
//代码实现了输出周六的日期。
|
||
|
||
使用了date的时间戳,使用了灵活设定strtotime的变化时间
|
||
|
||
**[html]** [view plain](http://blog.csdn.net/estom_yin/article/details/51920304)
|
||
[copy](http://blog.csdn.net/estom_yin/article/details/51920304)
|
||
|
||
1. **\<?php**
|
||
|
||
2. \$startdate = strtotime("Saturday");
|
||
|
||
3. \$enddate = strtotime("+6 weeks",\$startdate);
|
||
|
||
4.
|
||
|
||
5. while (\$startdate **\<** \$enddate) {
|
||
|
||
6. echo date("M d", \$startdate),"**\<br\>**";
|
||
|
||
7. \$startdate = strtotime("+1 week", \$startdate);
|
||
|
||
8. }
|
||
|
||
9. **?\>**
|
||
|
||
//代码实现了距离12月31还剩下的时间
|
||
|
||
**[php]** [view plain](http://blog.csdn.net/estom_yin/article/details/51920304)
|
||
[copy](http://blog.csdn.net/estom_yin/article/details/51920304)
|
||
|
||
1. \<?php
|
||
|
||
2. \$d1=strtotime("December 31");
|
||
|
||
3. \$d2=ceil((\$d1-time())/60/60/24);
|
||
|
||
4. echo "距离十二月三十一日还有:" . \$d2 ." 天。";
|
||
|
||
5. ?\>
|