简体   繁体   English

如何从多维数组Php的最后一个键中选择值

[英]How to select values from last key of multidimensional array Php

I want to select the values from the last key array. 我想从最后一个键数组中选择值。

I have this array: 我有这个数组:

Array
(
    [01] => Array
        (
            [cat_id] => 15
            [offset] => 4951
        )

    [02] => Array
        (
            [cat_id] => 15
            [offset] => 4251
        )

    [03] => Array
        (
            [cat_id] => 15
            [offset] => 4001
        )
)

To get the last key here is my code: 要获取最后一个键,这里是我的代码:

end($completed_steps);
$lastKey = key($completed_steps);

But how can I get the values of the last key? 但是,如何获取最后一个键的值? Like, I want to get cat_id and offset . 像,我想得到cat_idoffset

(sorry for late response, here's an additional note, I had to confirm this first from someone.) (对不起,您的回复太晚了,这里有个补充说明,我必须先向某人确认。)

NOTE : I want to store those values as variables. 注意 :我想将这些值存储为变量。 I think I have the idea now. 我想我现在有了主意。

Result of end() is the last value in array: end()结果数组中的最后一个值:

$values = end($completed_steps);
print_r($values);

Use below code for fetching the values of the last key in array :- 使用下面的代码获取数组中最后一个键的值:

$lastValue = end($completed_steps);
$cat_id = $lastValue['cat_id']);
$offset = $lastValue['offset']);

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

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