2014-12-13 168 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');