Solved

PHP find the index of an array element (long day)

Posted on 2013-05-22
3
275 Views
Last Modified: 2013-05-23
Hi,

It's been a long day, can someone put me out of my mysery:

I have a multi-dimentional array, (below) and I need to get the index sequence number of a specific element.

For example, I am looking for Household '15' so I want the result to be 12.

brain ache.  top points.

Array
(
    [HOUSEHOLD] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 9
            [3] => 20
            [4] =>
            [5] =>
            [6] =>
            [7] => 5
            [8] => 8
            [9] => 7
            [10] => 6
            [11] => 19
            [12] => 15
            [13] => 10
            [14] => 18
            [15] => 1
            [16] => 17
            [17] => 16
        )

    [NAME] => Array
        (
            [0] => SJ of Eastbourne
            [1] => New Player
            [2] => New Player
            [3] => WB of London
            [4] => ...
            [5] =>
            [6] =>
            [7] => New Player
            [8] => New Player
            [9] => SJ of Eastbourne
            [10] => New Player
            [11] => SJ of Eastbourne
            [12] => WB of London
            [13] => New Player
            [14] => SJ of Eastbourne
            [15] => New Player
            [16] => SJ of Eastbourne
            [17] => SJ of Eastbourne
        )
0
Comment
Question by:CrisThompsonUK
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 39188083
http://php.net/manual/en/function.array-search.php

$key = array_search("15",$arr["HOUSEHOLD"]);
0
 

Author Comment

by:CrisThompsonUK
ID: 39188719
Thanks Gonzo,

Will check this out  tomorro

Cris.
0
 

Author Closing Comment

by:CrisThompsonUK
ID: 39190236
Thanks Gonzo.

That's exactly what I tried, and convinced myself that it wasn't working!!!

Like I said - long day!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now