Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6895439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:54:31+00:00 2026-05-27T06:54:31+00:00

If 0 could be a possible key returned from array_search() , what would be

  • 0

If 0 could be a possible key returned from array_search(), what would be the best method for testing if an element exists in an array using this function (or any php function; if there’s a better one, please share)?

I was trying to do this:

if(array_search($needle, $haystack)) //...

But that would of course return false if $needle is the first element in the array. I guess what I’m asking is is there some trick I can do in this if statement to get it to behave like I want it? I tried doing these, but none of them worked:

$arr = array(3,4,5,6,7);

if(array_search(3, $arr) != false)  //...

if(array_search(3, $arr) >= 0)  //...

Appreciate the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:54:32+00:00Added an answer on May 27, 2026 at 6:54 am

    As an alternative to === and !==, you can also use in_array:

    if (in_array($needle, $haystack))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When fetching an array from MySQL the rows are typically returned with a key
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
I wonder how could is possible to make custom shape key on android keyboard.
Possible Duplicate: How to retrieve the values for the particular key from CFMutableDictionary In
Possible Duplicate: php values of one array to key of another array I have
One possible solution could be simple HTTP get or post request, but that wouldn't
What could be the possible causes for the following exception? System.PlatformNotSupportedException: 'ResourcePool' is not
Possible Duplicate: Could you explain STA and MTA? All ThreadPool threads are in the
Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i ,
Could anyone tell me if it is possible to use the flex 4 framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.