Solved

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

Posted on 2013-05-22
3
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

689 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