Limon
Limon

Reputation: 1793

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.

Is there a way to access to the value (2) without having to use a foreach loop?

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

Upvotes: 1

Views: 110

Answers (2)

R. Barzell
R. Barzell

Reputation: 674

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

Upvotes: 1

Sébastien
Sébastien

Reputation: 12139

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.

Upvotes: 2

Related Questions