简体   繁体   English

如何在php中获取多维数组中的最后一个值?

[英]How to get last value in multidimensional array in php?

I need to take every 10th value of this array? 我需要获取此数组的每10个值吗? Kindly help me to this questions? 请帮助我解决这个问题?

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
    )
)

use end() function. 使用end()函数。

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

Here's how you could get first ten entries of each array 这是获取每个数组的前十个条目的方法

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

This code may help. 此代码可能会有所帮助。

$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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM