0

I have an array (in PHP) that looks similar to:

$array_name [0] [0] ['value0']
                [1] ['value1']
                [2] ['value2']
            [1] [0] ['value0']
                [1] ['value1']
                [2] ['value2']

(this basically relates to $array_name['group']['subGroup']['value']

what I need is a way of telling it:

if $array_name[0] (group 1) then do something,

if $array_name[1] (group 2) do something else

but i can't see how I would do this (I'm sure the answer is right under my nose).

any help would be appreciated

1
  • What do you mean by if $array_name[0] (group 1) ? Commented Oct 5, 2012 at 9:30

1 Answer 1

4

Try this

foreach ( $array_name as $group_key => $group) {
  switch ($group_key) {
    case 0:
      // do something for group0
    break;
    case 1:
      // do something for group1
    break;
  }
}
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.