0

I have a multi dimensional array, like this:

array('name' => array('title'=>'Title','date'=>'Created'))

I store it as JSON 'array', and when I decode it, I want to reach every item by its number, so I want an indexed array.

How could I solve this in PHP?

Tim

3
  • Can you provide an example of what an indexed associative array is?? Commented Oct 28, 2009 at 18:32
  • Precisions needed. I don't see what you're trying to achieve here. What are those "items" you're talking about ? Commented Oct 28, 2009 at 18:32
  • So, I want to convert this associative array into a numeric array Commented Oct 28, 2009 at 18:36

1 Answer 1

2

According to your last comment Tim, this would achieve what you asked.. but I'm not sure why you would want this based off your initial question.

$foo = array('name' => array('title'=>'Title','date'=>'Created'));
$bar = array_values($foo);
print_r($bar); // Array ( [0] => Array ( [title] => Title [date] => Created ) ) 
Sign up to request clarification or add additional context in comments.

1 Comment

You wanted an ordered list(numeric array) of values from your hash (associative array). I suppose this is helpful in order to loop through the results in some order, but you lose the benefit of having the key. You could also just generate a separate array of keys that could be re-ordered more easily, by using array_keys($foo) instead.

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.