Solved

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

Posted on 2013-05-22
3
287 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

789 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