简体   繁体   English

在多维数组的第一个元素中选择数据-PHP

[英]Select Data in First Element of Multi-Dimensional Array - PHP

Is it possible to select data in a certain location, solely based on where it's located in an array? 是否可以仅根据数据在数组中的位置来在特定位置选择数据? I've tried slicing my array, but it shows information I still don't want. 我尝试切片数组,但是它显示了我仍然不想要的信息。

http://pastebin.com/68EMCSyZ http://pastebin.com/68EMCSyZ

In that array, I would only like to have [match_player_stats][84947759][5947051]'s data show. 在该数组中,我只想显示[match_player_stats] [84947759] [5947051]的数据。 But as you can see, there is another element in the same layer, which is why splicing doesn't work. 但是正如您所看到的,同一层中还有另一个元素,这就是为什么拼接不起作用的原因。 Basically, I want the first total element of [match_player_stats][84947759], in this case being [5947051]. 基本上,我想要[match_player_stats] [84947759]的第一个总计元素,在这种情况下为[5947051]。 Now don't get me wrong, I could easily do this if the numbers were static, but these numbers change based on a matchID entered- which is why I need to select based on "location" (if you will). 现在不要误会我的意思,如果数字是静态的,我可以轻松地执行此操作,但是这些数字根据输入的matchID进行更改-这就是为什么我需要根据“位置”进行选择(如果可以的话)的原因。

Thanks! 谢谢!

To get the first element of an array, you can use array_shift . 要获取数组的第一个元素,可以使用array_shift In your case: 在您的情况下:

$totalFirstValue = array_shift(array_shift($arr['match_player_stats']));

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

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