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

  • Home
  • SEARCH
  • 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 8663649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:02:23+00:00 2026-06-12T17:02:23+00:00

function array_searchRecursive( $needle, $haystack, $strict=false, $path=array() ) { if( !is_array($haystack) ) { return false;

  • 0
function array_searchRecursive( $needle, $haystack, $strict=false, $path=array() )
{
    if( !is_array($haystack) ) {
        return false;
    }

    foreach( $haystack as $key => $val ) {

        if( is_array($val) && $subPath = array_searchRecursive($needle, $val, $strict, $path) ) {
            $path = array_merge($path, array($key), $subPath);

            return $path;
        } else if( (!$strict && $val == $needle) || ($strict && $val === $needle) ) {

            $path[] = $key;
            return $path;
        }
    }
    return false;
}

Do any body suggest me the same funcitonality, that can be implemented in javascript.
reference http://www.php.net/manual/en/function.array-search.php#68424

  • 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-06-12T17:02:24+00:00Added an answer on June 12, 2026 at 5:02 pm

    This might give you a start. Not thoroughly tested or highly optimized, and assumes use of jQuery (shouldn’t be a big problem to replace the jQuery utilty functions with other implementations).

    function searchArrayRecursive(needle, haystack, strict) {
    
        function constructPath(needle, haystack, path, strict) {
            if (!$.isArray(haystack)) {
                return false;
            }
            var index;
            for (index = 0; index < haystack.length; index++) {
                var value = haystack[index];
                var currentPath = $.merge([], path);
                currentPath.push(index);
    
                if ((strict && value === needle) || (!strict && value == needle)) {
                    return currentPath;
                }
                if ($.isArray(value)) {
    
                    var foundPath = constructPath(needle, value, currentPath, strict);
                    if (foundPath) {
                        return foundPath;
                    }
                }
            }
    
            return false;
        }
    
    
        return constructPath(needle, haystack, [], strict);
    }
    

    http://jsfiddle.net/b8TxJ/2/

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

Sidebar

Related Questions

My function function array_push_assoc(&$array, $key, $value){ echo $key...$value.<p>; $array[$key] = $value; return $array; }
I have a function which must return one dimensional associate array, like $user_info[$index]=value where
I use stdClass to convert an array to an object, function array_to_object($array) { if(!is_array($array))
How can I setup the function array_keys to return all keys in my array
I'm using this function to search the (highest) array key when a value of
So there is this function Array.prototype.containsCaseInsensitive = function(obj) { var i = this.length; while
Here is my data returned from a CMS function: array ( 0 => stdClass::__set_state(array(
function append (array, value, dimension) { switch (dimension) { case 0: array.push( value );
Since the equals function in array only check the instance, it doesn't work well
The problem: To create a recursive array function that walks through a three dimensional

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.