PHP数组

View:http://www.php.net/manual/zh/ref.array.php
===========一维数组==================
$ages = array("Peter"=>32, 
              "Kate"=>30, 
              "Joe"=>34);
$ages['Peter'] = "32";
$ages['Kate'] = "30";
$ages['Joe'] = "34";
上面俩种方法功能相同
<?php

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

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

以上脚本的输出:

Peter is 32 years old.
===========二维数组==================

定义数组

$families = array
(
  "Griffin"=>array
  (
  "Peter",
  "Lois",
  "Megan"
  ),
  "Quagmire"=>array
  (
  "Glenn"
  ),
  "Brown"=>array
  (
  "Cleveland",
  "Loretta",
  "Junior"
  )
);
输出数组
Array
(
[Griffin] => Array
  (
  [0] => Peter
  [1] => Lois
  [2] => Megan
  )
[Quagmire] => Array
  (
  [0] => Glenn
  )
[Brown] => Array
  (
  [0] => Cleveland
  [1] => Loretta
  [2] => Junior
  )
)

输出上面的数组中的一个单一的值:

echo "Is " . $families['Griffin'][2] . 
" a part of the Griffin family?";

以上代码的输出:

Is Megan a part of the Griffin family?

你可能感兴趣的:(PHP数组)