Hi there,

I want to check if a value is in an array and if so, return the index of that value.

I can use the in_array() function to check if the index exists, but I can't find a way of returning the index once I know its there.

Any ideas?

Cheers, Jo

    Try the array_search function instead it can return the key of the element it has found.

    Mark.

      Once you know it is in the array, you can just use the index...

      if (in_array($needle, $haystack))
      echo $haystack[$needle];

        Write a Reply...