2014-12-13 139 views
-1

我想首先把所有的數據在一個多維數組,後來在另一個函數提取數據。這裏是我的數據存儲在數組中的方法:PHP多維數組

$data1 = array(); 

foreach ($line1 as $field => $label){ 
if (count($points) > 0 && isset($points[0]->$field)){ 
    $i = 0; 
    $total = count($points); 
    $total = $total > 95 ? 95 : $total; 
    foreach ($points as $point){ 
    if ($i >= $total){ 
     break; 
    } 

    $data1 []['line1'] = $point -> $field; 
    $i++; 
    } 


} 
} 

    foreach ($line2 as $field => $label){ 
if (count($points) > 0 && isset($points[0]->$field)){ 
    $i = 0; 
    $total = count($points); 
    $total = $total > 95 ? 95 : $total; 
    foreach ($points as $point){ 
    if ($i >= $total){ 
     break; 
    } 

    $data1 []['line2'] = $point -> $field; 
    $i++; 
    } 


} 
} 

然後我通過序列化URL中的數據將$ data1傳遞給一個函數。 $ data1然後在函數中反序列化並存儲在一個數組中。像這樣:

$data1 = unserialize(urldecode(stripslashes($_GET['mydata1']))); 

在這裏現在我想提取數組並將數組數據保存在兩個數組中。這是我想達到什麼:

$line1= store only all the data of $data1[]['line1'] 
$line2= store only all the data of $data1[]['line2'] 

如何實現這一目標?

回答

0

好的..我在這裏..發佈它,如果有人認爲它有用。

$line1 = array_column($data1, 'line1'); 
$line2 = array_column($data1, 'line2');