0

Array looks like below :

  Array
    (
        [0] => Array
            (
                [memberid] => 5203
            )

        [1] => Array
            (
                [memberid] => 494
            )

        [2] => Array
            (
                [memberid] => 1053
            )

        [3] => Array
            (
                [memberid] => 1081
            )
    )

How can i find-out the outer array index (such as 0,1,2) using inner array.

3
  • 1
    Do you want to all index or just one. If you iterate above array using foreach loop you have that key. Missing usecase. Commented Oct 13, 2017 at 5:16
  • I want to know the outer array index of the member which i am choosing. What I mean is, if i am choosing the member with member id 1081, i wanna display the index 3. Help please Commented Oct 13, 2017 at 5:22
  • 1
    and how you choose member id 1081 ? By means of index or loop. How do you reach id 1081? Help Commented Oct 13, 2017 at 5:47

1 Answer 1

0

You can iterate the outer array, and save the key if the current inner array value matches like this:

$outerKey = null;
foreach($outerArray as $key => $member){
    if($member['memberid'] == 1081){
        $outerKey = $key;
        break;
    }
}
echo $outerKey; // it will print 3
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.