Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.

746 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

12 Experts available now in Live!

Get 1:1 Help Now