fonksiyonu php-recursive 2d dizi

0 Cevap php

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.

Yani sadece bu çözmek için başka olduğunu merak ediyorum. Ben özyineleme kullanmadan demek.

kod örneği:

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

0 Cevap