PHP 数组

 1         // 这里用数字来作为索引
 2         $myArray = array(2012, 'blue', 5, 'BMW');
 3 
 4         // 这个用关键字作为索引
 5         $myAssocArray = array('year' => 2012,
 6                         'colour' => 'blue',
 7                         'doors' => 5,
 8                         'make' => 'BMW');
 9             
10         // This code will output "blue".
11         echo $myArray[1];
12         echo '<br />';
13         echo $myAssocArray['colour'];
14         //循环输出数组结果
15         foreach ($myAssocArray as $ingredient=>$include) {
16         echo $include . ' ' . $ingredient . '<br />';
17       }
18 
19         //数组里面有数组
20         $deck = array(array('2 of Diamonds', 2),
21                       array('5 of Diamonds', 5),
22                       array('7 of Diamonds', 7));    
23             //输出  You have the 7 of Diamonds!
24           echo 'You have the ' . $deck[2][0] . '!';
原文地址:https://www.cnblogs.com/linuxroot/p/3165890.html