php - Why I'm the loop is breaking and getting error even after not satisfying the condition? -


i've following code snippet:

        $asupportedimages = array('jpg', 'gif', 'png');         foreach($vshare $file) {           if(!in_array(pathinfo($file, pathinfo_extension), $asupportedimages))             $errarr = 'file extension of image wrong';             echo $errarr;                           break;         } 

the array $vshare follows(output of print_r($vshare);):

array       (           [img_0004.jpg] => array               (                   [0] => https://www.filepicker.io/api/file/uyukzvhergufb0enrbjo               )        ) 

i'm not understanding why loop getting broken , getting error "file extension of image wrong" after file having extension present in array $asupportedimages?

please me.

thanks.

you should use below code,
image name key of array, , using value in extension check

edit : other users said, missing {} brackets in if condition

note : when want execute 1 statement dont neet use curly braces. if want execute multiple statements must wrap statements curly braces.

   $asupportedimages = array('jpg', 'gif', 'png');     foreach($vshare $key=> $value) {       if(!in_array(pathinfo($key, pathinfo_extension), $asupportedimages))         {              $errarr = 'file extension of image wrong';              echo $errarr;                            break;         }     } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -