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 1042631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:32:19+00:00 2026-05-16T15:32:19+00:00

I need to have an array_search search my array strictly making sure that the

  • 0

I need to have an array_search search my array strictly making sure that the item is identical (meaning the whole thing is the same thing as the input value). I know about the third variable in a array_search() function in PHP – the Strict one, but I don’t want it to check if its the same instance, as it is not. How would I do this?

Here is the code I’m currently using:

array_search(some, array(someItem,anothervariable, yetanothervariable, some)); 
//output - 0 (the first item) which contains some but isn't exactly some.

Requested output:

Instead of outputting the first item that contains some, someItem, it would output the key for the last item, 3, that is the exact search value.

  • 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-16T15:32:19+00:00Added an answer on May 16, 2026 at 3:32 pm

    Are you open to using a foreach loop instead of array_search?

    If so try this:

    $haystack = array('something', 'someone', 'somewhere', 'some');
    $needle = 'some';
    
    foreach($haystack as $key=>$straw){
        if($straw === $needle){
            $straws[$key] = $straw;
            }
        }
    
    print_r($straws);
    

    it will print

    Array ( [3] => some ) 
    

    Or you could use array_keys() with the search value specified.

    Then, using the same $haystack and $needle above:

    $result = array_keys($haystack,$needle,TRUE);
    print_r($result);
    

    This returns:

    Array ( [0] => 3 ) 
    

    The first argument is the array to return keys from, The second arg is the search value, if you include this arg, then only keys from array elements that match the search value are returned. Including the third boolean arg tells the function to use match type as well (===).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have the need to search a javascript array that contains objects. I
I have an array in javascript that I need to join and send through
I have an array that contains several domain names. I need to replace those
I have an array of search terms, and a setence. I need to test
I have an array with dictionaries, and need to search trough the array and
So I have a search controller that returns a array of Object IDs (in
What does array_search() return if nothing was found? I have the need for the
How do i explode this string '||25||34||73||94||116||128' i need to have a array like
I am doing server-side javascript and i need to have a typed array of
I have an array which i need to sort its elements by occurrence then

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.