博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
知识点五:关于数组的几个基本操作
阅读量:4991 次
发布时间:2019-06-12

本文共 2505 字,大约阅读时间需要 8 分钟。

 
<?
php
/*
* 简单的数组定义与访问
*/
echo
"
简单的数组定义与访问<br>
"
;
echo
"
############################################################<br>
"
;
$address
=
array
(
5
);
$address
[
0
]
=
"
福州
"
;
$address
[
1
]
=
"
厦门
"
;
$address
[
2
]
=
"
漳州
"
;
$address
[
3
]
=
"
泉州
"
;
$address
[
4
]
=
"
宁德
"
;
$address
[
5
]
=
"
南平
"
;
$address
[
6
]
=
"
龙岩
"
;
echo
"
我现在住在
$address
[1]<br>
"
;
echo
"
############################################################<br><br><br>
"
;
/*
* 数组遍历
*/
echo
"
通过for循环进行数组遍历<br>
"
;
echo
"
############################################################<br>
"
;
for
(
$index
=
0
;
$index
<
count
(
$address
);
$index
++
){
print
(
"
数组中第
"
.
$index
.
"
个的地区
$address
[
$index
]为<br>
"
);
}
echo
"
############################################################<br><br><br>
"
;
/*
* 数组初始化
*/
echo
"
数组初始化,并通过日期函数得到当前月份的数字,输出相关数组下标的内容<br>
"
;
echo
"
############################################################<br>
"
;
$arrMonth
=
array
(
"
January
"
,
"
February
"
,
"
March
"
,
"
April
"
,
"
May
"
,
"
June
"
,
"
July
"
,
"
August
"
,
"
September
"
,
"
October
"
,
"
November
"
,
"
December
"
);
date_default_timezone_set(
"
utc
"
);
//
设置默认时区
$month
=
date
(
"
m
"
);
echo
"
数组结构为
"
;
print_r
(
$arrMonth
);
echo
"
当前是第
"
.
$month
.
"
月,他的英文是
"
.
$arrMonth
[
$month
-
1
]
.
"
<br>
"
;
echo
"
############################################################<br><br><br>
"
;
/*
*数组初始化,并定义键,然后通过键值访问数组
*/
echo
"
数组初始化,并定义键,然后通过键访问数组<br>
"
;
echo
"
############################################################<br>
"
;
$arrMonth
=
array
(
"
Jan
"
=>
"
January
"
,
"
Feb
"
=>
"
February
"
,
"
Mar
"
=>
"
March
"
,
"
Apr
"
=>
"
April
"
,
"
May
"
=>
"
May
"
,
"
Jun
"
=>
"
June
"
,
"
Jul
"
=>
"
July
"
,
"
Aug
"
=>
"
August
"
,
"
Sept
"
=>
"
Septmber
"
,
"
Oct
"
=>
"
October
"
,
"
Nov
"
=>
"
November
"
,
"
Dec
"
=>
"
December
"
);
echo
"
通过英文缩写Aug 访问数组
"
.
$arrMonth
[
"
Aug
"
]
.
"
<br>
"
;
echo
"
############################################################<br><br><br>
"
;
echo
"
下面通过Foreach遍历数组<br>
"
;
echo
"
############################################################<br>
"
;
foreach
(
$arrMonth
as
$key
=>
$value
){
echo
"
&nbsp;&nbsp;=>键是
$key
,值是
$value
<br>
"
;
}
echo
"
############################################################<br><br><br>
"
;
/*
* 定义多维数组
*/
echo
"
定义二维数组<br>
"
;
$arrArea
=
array
(
"
华东地区
"
=>
array
(
"
福建
"
,
"
浙江
"
)
,
"
华北地区
"
=>
array
(
"
北京
"
,
"
天津
"
));
echo
"
华东地区=>
"
.
$arrArea
[
"
华东地区
"
][
0
]
?>

转载于:https://www.cnblogs.com/PHP001/archive/2011/07/08/2100584.html

你可能感兴趣的文章
webpack安装问题
查看>>
Qt学习记录--Qt::CaseSensitive
查看>>
你的灯还亮着吗阅读笔记之一
查看>>
python介绍
查看>>
Unity-Editor按钮和菜单显示
查看>>
SharePoint InfoPath 保存无法发布问题
查看>>
word2vec:主要概念和流程
查看>>
Java - MyBites 逆向工程
查看>>
104. Maximum Depth of Binary Tree
查看>>
Python--变量作用域
查看>>
2017-2018-1 20155235 《信息安全系统设计基础》第九周学习总结
查看>>
!!和??
查看>>
matlab演奏卡农 Cripple Pachebel's Canon on Matlab
查看>>
apache的MPM机制-prefork
查看>>
js的一些实用的小技巧
查看>>
vue-cli中理不清的assetsSubDirectory 和 assetsPublicPath
查看>>
iOS的UILabel设置居上对齐,居中对齐,居下对齐
查看>>
最流行的android组件大全
查看>>
【Android自定义控件】支持多层嵌套RadioButton的RadioGroup
查看>>
Swift - 内存泄露原因(循环强引用)及解决办法
查看>>