国外好的室内设计网站,企业类型,某旅行社网站建设论文,网页结构有哪几种关联数组 注意#xff1a;先声明关联数组 一、定义关联数组 方法一
#一次赋一值
#数组名[索引]变量值
[rootlocalhost ~]# declare -A ass_array1
[rootlocalhost ~]# ass_array1[index1]pear
[rootlocalhost ~]# ass_array1[index2]apple
[rootlocalhost ~]# ass_array1[ind…关联数组 注意先声明关联数组 一、定义关联数组 方法一
#一次赋一值
#数组名[索引]变量值
[rootlocalhost ~]# declare -A ass_array1
[rootlocalhost ~]# ass_array1[index1]pear
[rootlocalhost ~]# ass_array1[index2]apple
[rootlocalhost ~]# ass_array1[index3]orange
[rootlocalhost ~]# ass_array1[index4]peach[rootlocalhost ~]# echo ${ass_array1[*]} #查看
peach pear apple orange 方法二
#一次赋多个值
[rootlocalhost ~]# declare -A ass_array2
[rootlocalhost ~]# ass_array2([index1]tom [index2]jack [index3]alice [index4]bash shell)[rootlocalhost ~]# echo ${ass_array2[*]} #查看
bash shell tom jack alice
[rootlocalhost ~]# echo ${!ass_array2[*]}
index4 index1 index2 index3
[rootlocalhost ~]# echo ${#ass_array2[*]}
4 二、查看数组
[rootlocalhost ~]# declare -A
declare -A ass_array1([index4]peach [index1]pear [index2]apple [index3]orange )
declare -A ass_array2([index4]bash shell [index1]tom [index2]jack [index3]alice )三、访问数组元素
[rootlocalhost ~]# echo ${ass_array2[index2]} #访问数组中的第二个元素
[rootlocalhost ~]# echo ${ass_array2[]}
[rootlocalhost ~]# echo ${ass_array2[*]} #访问数组中所有元素
[rootlocalhost ~]# echo ${!ass_array2[]} #获得数组元素的个数
[rootlocalhost ~]# echo ${#ass_array2[]} #获得数组元素的索引