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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:12:20+00:00 2026-06-18T07:12:20+00:00

I have this difficult task (for me at least). This is abstract question, mathematical

  • 0

I have this difficult task (for me at least).
This is abstract question, mathematical i’d say.
Let’s assume I have 2 inputs:

  1. a keyword (string)
  2. a number (deepness level)

and submit button.

This keyword returns me 8 other keywords from a database that are similar to this string.
And for each of that 8 keywords I need to call same function that will return me another 8 similar keywords of all these 8 strings I have already returned.
Here comes the “level” number. I need to go deeper inside every of returned string depending on level number I entered.

For example: If the level number is 2, then we will call the function 9 times. First time for the original keyword, and 8 times for each returned keyword.
If the level number is 3, then the function will be called 73 times. Like in the previous example, but plus for another 8 keywords we have returned. I think there will be a couple of loops inside loops, but can’t figure it out by myself. Will appreciate your suggestions.

Here’s the main code that I have wrote which is probably unsufficient:

$keywords = preg_split('/$\R?^/m', trim($_POST['keyword']));
$keywords = array_map('trim', $keywords);
$level = $_POST['level'];
if (!$level || $level < 2) {
    echo '<b>Level was either 1 or null</b>';
}
foreach ($keywords as $keyword) {
    $results = getResults($keyword);
    if ($level && $results) {
        for ($i = 0; $i < sizeof($results); $i++) {
            $results1 = getResults($results[$i]);
            for ($j = 0; $j < $level; $j++) {
                $results1 = getResults($results1[$i])
            }
        }
    }
}

The output should be something like this:

1->
   2
   ->
      3
      3
      3
      3
      3
      3
      3
      3
   2->
   2->
   2->
   2->
  • 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-18T07:12:21+00:00Added an answer on June 18, 2026 at 7:12 am

    You need to understand what recursion means and how you can use it in your code. Basically you need to call the same function inside itself, n times where n is the deepness level of your request.

    Start with some little examples like Fibonacci series, and you will find the way to implement your function.

    All is based on a condition ($deepness > 0).

    Here’s a little suggestion (in pseudocode) based on what I understood.

    function findSimilar($words,$deepness) {
        if($deepness == 0) {
            return similarWordsOf($words);
        } else {
            return similarWordsOf(findSimilar($words,$deepness -1));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a difficult regex. I have this expression to detect
I'm not sure how difficult this but I have an array and would like
I have tried making a fiddle for this, but it's been too difficult to
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have a very difficult task, that I think exceeds my level of knowledge
why is it such a difficult task to find a String function to center
Let me first say that I have quite a lot of Java experience, but
It's quite difficult to have a good title of my question. From what I
I have encounters this abap snippet that I have difficulty to comprehend. call function
I am having a bit of difficulty with this current code I have set

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.