关联数组

有三种数组类型:

数值数组
带有数字 ID 键的数组

例子 1

在这个例子中,会自动分配 ID 键:

$names = array("Peter","Quagmire","Joe");

例子 2

在这个例子中,我们人工分配的 ID 键:

$names[0] = "Peter";
$names[1] = "Quagmire";
$names[2] = "Joe";

 

关联数组
数组中的每个 ID 键关联一个值
<?php

$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";

echo "Peter is " . $ages['Peter'] . " years old.";
?>

以上脚本的输出:

Peter is 32 years old.
多维数组
包含一个或多个数组的数组
Advertisements
此条目发表在PHP分类目录。将固定链接加入收藏夹。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s