SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using wildcards in in_array

    I want to search element [21] of a multi-dimensional array with in_array. So I have an array that is ['field'][x][21] where x is the element number and I want to see if the value I am looking for is in element #21 in any of the x elements of ['field']. I know I can do this with a for type statement but was wondering if there was some kind of wildcard I could use to say search all [x] elements for item [21]. Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Use a foreach loop to provide a $key $item lookup service.

    Code php:
    foreach ($arr['field'] as $key => $item) {
        if ($item[21] === $value) {
            echo 'Found ' . $value . ' in ' . $key;
        }
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •