php多维数组值变量

时间:2013-12-07 04:41:15

标签: php arrays variables

我忽视了一些事情,但我已经尝试了一切我能想到的将这些值变为变量。

现有数组的创建方式如下:     $ compdata [] = array($ currentTime,$ indiff,$ outdiff,$ totaldiff);

这是数组的转储:

Array (   
[0] => Array ( [0] => 1385955600 [1] => 29749073 [2] => 116376416 [3] => 146125489 )  
[1] => Array ( [0] => 1385956200 [1] => 2628480405 [2] => 18073170501 [3] => 20701650906 )   
[3] => Array ( [0] => 1385957400 [1] => 2728527955 [2] => 16495107227 [3] => 19223635182 )  
)

我的问题是如何使用foreach或while循环将这些值转换为变量,如:

$time = $value[0];  
$inbound = $value[1];  
$outbound = $value[2];  
$total = $value[3];  

我知道我必须做些什么才能获得嵌套值。 。 。

非常感谢。

2 个答案:

答案 0 :(得分:1)

你真的错过了循环:

foreach ($compdata as $value) {
    $time = $value[0];  
    $inbound = $value[1];  
    $outbound = $value[2];  
    $total = $value[3]; 
}

答案 1 :(得分:0)

您可以使用list作为

执行此操作
foreach ($compdata as $array) 
    {
    list($time,$inbound,$outbound,$total)=$array;

    }