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);
}
}