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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:37:54+00:00 2026-05-16T18:37:54+00:00

I have a 2d array say, Array A[60][150] and have another array, Array B[60][150].

  • 0

I have a 2d array say, Array A[60][150] and have another array, Array B[60][150].
Now what I am trying to do is:

Given a point in Array A say x,y i want to access its neighbors to find similarity between the two elements. if they are similar then find its neighbors.
So right now i am using recursive function to do it. But its throws an error saying maximum execution time has exceeded or out of memory.

So I am just wondering is there any other to solve this. I mean without using recursion.

code example:

           protected function find_neighbor($y,$x,$garray,$gr)
       {
        $r=$garray[$y][$x-1]['red'];
        if(true){
            $this->find_neighbor($y,$x-1,$garray,$gr);
        }

        $r=$garray[$y-1][$x-1]['red'];
        if(true){
            $this->find_neighbor($y-1,$x-1,$garray,$gr);
        }

        $r=$garray[$y-1][$x]['red'];
        if(true){
            $this->find_neighbor($y-1,$x,$garray,$gr);
        }

        $r=$garray[$y-1][$x+1]['red'];
        if(true){
            $this->find_neighbor($y-1,$x+1,$garray,$gr)
        }

        $r=$garray[$y][$x+1]['red'];
        if(true){
            $this->find_neighbor($y,$x+1,$garray,$gr);      
        }

        $r=$garray[$y+1][$x+1]['red'];
        if(true){
            $this->find_neighbor($y+1,$x+1,$garray,$gr);
        } 

        $r=$garray[$y+1][$x]['red'];
        if(true){
                $this->find_neighbor($y+1,$x,$garray,$gr);  
        } 

        $r=$garray[$y+1][$x-1]['red'];
        if(true){
            $this->find_neighbor($y+1,$x-1,$garray,$gr);
        }
}
  • 1 1 Answer
  • 1 View
  • 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-16T18:37:55+00:00Added an answer on May 16, 2026 at 6:37 pm

    Untested:

    $range = 3;
    foreach ($A as $A1=>$tmp) {
        foreach ($tmp as $A2=>$value) {
            for ($x=0-$range; $x<=$range; $x++) {
                for ($y=0-$range; $y<=$range; $y++) {
                    $F1 = $A1+$x;
                    $F2 = $A2+$y;
                    if (isset($A[$F1][$F2])) {
                        print "A[{$A1}][{$A2}] is close to A[{$F1}][{$F2}]<br>";
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three array..say array1,array2,array3. All these arrays contains dictionary.Now, I want to copy
i have an array say array1(asd,ard,f_name,l_name) now i want to replace some value as
I have an array lets say a = { 1,4,5,6,2,23,4,2}; now I have to
lets say i have one array a = numpy.arange(8*6*3).reshape((8, 6, 3)) #and another: l
Lets say I have an array of length n and I want to pick
I have the array variable say $value, and it has the below given array
What I want to do is following. Lets say we have array like that
I have an array of values say arr(0)=Sam arr(1)=1452 arr(2)=NY I want to generate
I currently have an array of values (business_id's) lets say its Array ( [0]
Suppose i have array of characters. say char x[100] Now, i take input from

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.