2008/08/05

PHP陣列的處理

最近正在寫一個翻譯管理的程式,需要使用到:array_push和array_shift,以下是相關的說明。

在作array_push前,要注意一定得先作一個陣列才可以插入。
另外,無論是array_push和array_shift都可以處理多維陣列,以下是一個範例:
<?php

$cars = array ("0" => array ("0" => 0, "1" => 0, "2" => 0));

$car1 = array ("BMW" => array ("Money" => 200, "Color" => "Black", "Type" => "328i"));
$car2 = array ("MAZDA" => array ("Money" => 70, "Color" => "Blue", "Type" => "323"));
$car3 = array ("HONDA" => array ("Money" => 40, "Color" => "White", "Type" => "City"));
$car4 = array ("VOLVO" => array ("Money" => 100, "Color" => "Pink", "Type" => "s40"));

array_push($cars, $car1, $car2, $car3, $car4); // 插入四個多維陣列
print_r($cars);

array_shift($cars); //移掉最前面的陣列
print_r($cars);
?>

沒有留言:

張貼留言