jeudi 3 mars 2016

Cannot redeclare App\funtion_name()

I have a function

function getImg($img,$str,$input){
    // dd($img);

    $img_path = public_path().'/images/photos/devices/'.$img.'.jpg';
    if(file_exists($img_path)){
        if(strpos($input,$str)){
            return $img;
        }else{
            return 'no-img';
        }
    }else{
        return 'no-img';
    }
}


Then, I call it like this

getImg('phone','phone',$input);

Why do I keep getting this error ?

Cannot redeclare App\getImg()


The whole function

public static function img($input){

    $img_path = public_path().'/images/photos/devices/';
    $images = scandir($img_path, 1);

    $devices = [];
    foreach($images as $i=>$image){
        if($image != '.' && $image != '..' && $image != '.DS_Store'){
            $name  = str_replace('.jpg', '', $image);
            $devices[$i]['name'] = $name;
        }
    }


    // dd($devices);
    // dd($input);


    foreach ($devices as $i=>$device) {

        $matches = array_filter($devices, function($device) use ($input) {
          return strpos($input, $device['name']) !== FALSE;
        });

        if(count($matches) > 0){

            foreach ($matches as $match) {

                $input = $match['name'];

                $img_path = public_path().'/images/photos/devices/'.$input.'.jpg';
                if(file_exists($img_path)){
                    return $input;
                }else{
                    return 'no-img';
                }

            }
        }else{

            // dd($input);

            function getImg($img,$str,$input){
                // dd($img);

                $img_path = public_path().'/images/photos/devices/'.$img.'.jpg';
                if(file_exists($img_path)){
                    if(strpos($input,$str)){
                        return $img;
                    }else{
                        return 'no-img';
                    }
                }else{
                    return 'no-img';
                }
            }

            getImg('phone','phone',$input);
            getImg('ipad','ipad',$input);
            getImg('iphone','iphone',$input);
            // getImg('imac','imac');

        }

    }

}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Sly4De
via IFTTT

Aucun commentaire:

Enregistrer un commentaire