2017-10-12 155 views
0

我需要采取这个数组的每10个值?请帮助我解决这个问题?如何在php中获取多维数组中的最后一个值?

array (
[0] => array 
    (
     [0] => 88% 
     [1] => 88% 
     [2] => 88% 
     [3] => 88% 
     [4] => 88% 
     [5] => 88% 
     [6] => 88% 
     [7] => 88% 
     [8] => 88% 
     [9] => 88% 
     [10] => 88% 
    ) 
[1] => Array 
    (
     [0] => 401 MByte 
     [1] => 401 MByte 
     [2] => 401 MByte 
     [3] => 401 MByte 
     [4] => 401 MByte 
     [5] => 401 MByte 
     [6] => 401 MByte 
     [7] => 401 MByte 
     [8] => 401 MByte 
     [9] => 401 MByte 
     [10] => 401 MByte 
    ) 
[2] => Array 
    (
     [0] => 452,947 MByte 
     [1] => 451,651 MByte 
     [2] => 450,626 MByte 
     [3] => 451,137 MByte 
     [4] => 452,628 MByte 
     [5] => 454,383 MByte 
     [6] => 456,065 MByte 
     [7] => 454,829 MByte 
     [8] => 453,094 MByte 
     [9] => 451,930 MByte 
     [10] => 451,923 MByte 
    ) 
) 
+1

你想每个数组的前10个条目? –

回答

0

这里是你如何可以得到每个阵列

$arr = array_map(function($v) { 
      return array_slice($v, 0, 9); 
     }, $arr); 
var_dump($arr); 
0

使用end()函数。

foreach($yourArry as $one) { 
    echo end($one) ; 
} 
0

此代码可以帮助的前十个条目。

$myArray = array (
[0] => array 
    (
     [0] => 88% 
     [1] => 88% 
     [2] => 88% 
     [3] => 88% 
     [4] => 88% 
     [5] => 88% 
     [6] => 88% 
     [7] => 88% 
     [8] => 88% 
     [9] => 88% 
     [10] => 88% 
    ) 
[1] => Array 
    (
     [0] => 401 MByte 
     [1] => 401 MByte 
     [2] => 401 MByte 
     [3] => 401 MByte 
     [4] => 401 MByte 
     [5] => 401 MByte 
     [6] => 401 MByte 
     [7] => 401 MByte 
     [8] => 401 MByte 
     [9] => 401 MByte 
     [10] => 401 MByte 
    ) 
[2] => Array 
    (
     [0] => 452,947 MByte 
     [1] => 451,651 MByte 
     [2] => 450,626 MByte 
     [3] => 451,137 MByte 
     [4] => 452,628 MByte 
     [5] => 454,383 MByte 
     [6] => 456,065 MByte 
     [7] => 454,829 MByte 
     [8] => 453,094 MByte 
     [9] => 451,930 MByte 
     [10] => 451,923 MByte 
    ) 
); 

$my_values = array(); 
foreach($myArray as $a) { 
    if(isset($a[10])) 
     $my_values[] = $a[10]; 
} 

var_dump($my_values); //to check the values 
相关问题