Announcement

Collapse
No announcement yet.

How to test every element of an array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to test every element of an array

    I have an array of numbers and I have another number which I want to test to see if it is in the array. How do I do this?

    So, if I have the numbers 4, 5, and 6 in the array called $list and I have a variable called $test which contains the number 5. How do I test the contents of the variable against every item in the array.

    Thanks ... ummm probably to my hero MAX!!

    -JRW
    LostDiscussion.com - Fan base community for ABC's Lost | Club-tC.com - Scion tC Enthusiast Site | PcTechTalk.com - What's your issue? | eInvesting.com - Play the Market, Learn Investing, WIN!

  • #2
    bool in_array ( mixed needle, array haystack [, bool strict])

    PHP Docs: in_array()

    How's that for service?

    Comment


    • #3
      A+ service once again. I'll give it a try in a bit.

      Thanks again,

      -JRW
      LostDiscussion.com - Fan base community for ABC's Lost | Club-tC.com - Scion tC Enthusiast Site | PcTechTalk.com - What's your issue? | eInvesting.com - Play the Market, Learn Investing, WIN!

      Comment


      • #4
        You might want to note that in_array() returns a boolean value. If you want the key where the element was found, you'll need to use array_search().

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        X