1

I have an array which looks like this:

$example = [
             ['rendered'][0]['rendereditem1']
             ['rendered'][4]['rendereditem2 and more']
             ['rendered'][2]['rendereditem3']
]

Now I want to iterate with foreach to get the contents of 0,4,2!

Normally I would write:

foreach($example as $value){
    print $value['rendered'][int which is the same everywhere];
}

But that is obviously not working because the array name is always different...how could I iterate in this case?

1
  • yes ;P especially this part [int which is the same everywhere] Commented May 9, 2013 at 13:10

1 Answer 1

1

Simply add a second loop to iterate over the members :

foreach($example as $value) {
  foreach($value['rendered'] as $key=>$item) {
    // Do what you want here, $key is 0,4,2 in your example
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.