简体   繁体   English

在不使用foreach循环的情况下访问3d数组

[英]Accessing a 3d array without using foreach loop

Let's say I have a 3D array and I don't want to access it through the key names. 假设我有一个3D数组,但我不想通过键名访问它。

Is there a way to access to the value (2) without having to use a foreach loop? 有没有一种方法可以访问值(2),而不必使用foreach循环?

array (size=1)
'type' => 
 array (size=1)
  'registered' => string '2' (length=1)

It is not possible without a loop. 没有循环就不可能。

  1. If you don't want to use keys and all that matters is the position within the array then use a numerical array. 如果您不想使用键,而仅需注意数组中的位置,则可以使用数字数组。
  2. If you really want to use an associative array and you need to find the key at a specified index, then at some point you will need to loop through your array. 如果您确实要使用关联数组,并且需要在指定的索引处找到键,那么在某些时候,您将需要遍历数组。

You could try serializing your array and working with the serialized structure. 您可以尝试序列化阵列并使用序列化的结构。 Not saying this is good or even viable, but it might do what you want. 并不是说这是好的甚至是可行的,但是它可能会做您想要的。

You can find out more about serialize here: http://php.net/manual/en/function.serialize.php 您可以在此处找到有关序列化的更多信息: http : //php.net/manual/en/function.serialize.php

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

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