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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:06:03+00:00 2026-06-05T12:06:03+00:00

I have a function function GetArrKey( $findArr, $key_arr, $depth=0 ) { if( count($key_arr) <=

  • 0

I have a function

function GetArrKey( $findArr, $key_arr, $depth=0 )
{
  if( count($key_arr) <= $depth || !array_key_exists($key_arr[$depth], $findArr) )
    return NULL;
  else if( count($key_arr) == $depth+1 )
    return $findArr[$key_arr[$depth]];

  return self::GetArrKey( $findArr[$key_arr[$depth]], $key_arr, $depth+1 );
}

That searches an array and returns the part of the array that matches what I need.

The only problem is it seems to be returning the exact same value. For example, I have this function in a foreach loop

foreach($e as $k => $v) {
  $value = GetArrayKey(array,$k);
  print_r($value);
}

and it’s printing the exact same value 5 times (but the $k that I am using to search for is different each time).

I’m assuming it is because of the return self::GetArrKey but I can’t seem to fix it.

Examples…

tweet-19486731414564564
Tweet 1
tweet-19486778435455556
Tweet 1
tweet-19703966855465458
Tweet 1
tweet-19842914654654650
Tweet 1

But it should do

tweet-19486731414564564
Tweet 1
tweet-19486778435455556
Tweet 2
tweet-19703966855465458
Tweet 3
tweet-19842914654654650
Tweet 4
  • 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-05T12:06:05+00:00Added an answer on June 5, 2026 at 12:06 pm

    I believe your problem is in the last line of your recursive function:

    return self::GetArrKey( $findArr[$key_arr[$depth]], $key_arr, $depth+1 );
    

    This means that the function will be called again, until you hit a base case. The base case will return, and this function does not modify that case. Therefore all calls to the recursive function will return only the result of the base case, which is not what you want in this case because you’re looking for a response rather than performing some function recursively.

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

Sidebar

Related Questions

i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function getCartItems in cart.js and I want to call that function in
I have function Start() that is fired on ready. When I click on .ExampleClick
Inside my Controller i have function that runs after user clicks on item, which
i have function which return list as given below. List<User> lstUsers = SearchUsers(searchText); which
I have function that have been colled in stored procedure. The function returns a
i have function that changes background color of element and src of image. in
I have this method: protected function _sendRequest($url, $method, Busca_Cxense_Data $data, $get = null) {
I have function getMemory() which returns VARIANT (mfc). It is said that in ulVal
I have function that has : ob_start(); //Include of some files $content = ob_get_contents();

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.