php – Is there anyeay to get my code cleaner and more eficcient?


I’m wondering if there’s abyway ti get this code cleaner and more efficient mainly in the filters.

Any question please comment 🙂

class RouteController extends Controller {
    public function getRoutes()
    {
        
        //Get all the routes.
        $routes = Route::getRoutes();

        
        //Setting up the vars
        $array = ('');

        
        
        foreach ($routes as $route) {
            $condicional = substr($route->getName(), 0, 3);
            $found = FALSE;

           //Filtering the routes with rt_ prefix
            if ($condicional == 'rt_') {

                 //Filering duplicates
                foreach ($array as $item) {
                    if ($item == $route->getName()) {
                        $found = TRUE;


                    }

                }

                
                //Echo without duplicates
                if ($found == FALSE) {
                    $array() = $route->getName();

                }
            }
        }

        return response()->json($array, 200);

    }


}