2016年2月14日 星期日

php Advanced : array multi

Multidimensional Arrays


PHP - Two-dimensional Arrays

A two-dimensional array is an array of arrays (a three-dimensional array is an array of arrays of arrays).
First, take a look at the following table:
NameStockSold
Volvo2218
BMW1513
Saab52
Land Rover1715

$cars = array
  (
  array("Volvo",22,18),
  array("BMW",15,13),
  array("Saab",5,2),
  array("Land Rover",17,15)
  );

<?php
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>

執行結果如下:









4 則留言:

  1. C# for loop structure of C# is like an all-in-one looping utility. The C# for loop acts like the while loop only with some extra features. The syntax of a C# for loop is quite different compared to the other two looping structures.

    回覆刪除