1

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)
11
  • Can you post a print_r() output of your array? Commented Nov 1, 2013 at 18:55
  • If you don't know the key names, do you know the value? Commented Nov 1, 2013 at 18:56
  • you can use array_keys($array) to get the keys, but foreach is a better solution. Commented Nov 1, 2013 at 18:58
  • it's not that i don't know the key, i just don't want to use them Commented Nov 1, 2013 at 19:00
  • What should be the reason for not to? I'm curious about this particularity Commented Nov 1, 2013 at 19:02

2 Answers 2

2

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.
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

i've tried serializing (not that way), but founded that wasn't much helpful for building the query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.