0

am using readdir to get all the image from the folder like

function get_user_image($valid_user){
    $rootdir = "../../../user/".$valid_user;
    $dir = opendir("../../../user/".$valid_user);
    $image = array();
    scan_image($image,$rootdir);
    print_r($image);
}
function scan_image($arr,$root){
    $dir = opendir($root);
    while (false!=($file=readdir($dir))){
        if($file!='.'&&$file!='..'){
            $isfile = strripos($file, ".");
            if($isfile)
            {
                $filetype = substr($file,$isfile+1);
                if($filetype=="jpg")
                {
                    //echo $file."</br>";
                    array_push($arr, $file);

                    echo sizeof($arr)."</br>";

                }
            }
             else
            {
                 $curpath = $root."/".$file;
                 scan_image($arr,$curpath);
            }
        }

     }
 }

but the print_r($image) is empty,however,the echo sizeof($arr) is right, any idea why?

paynestrike
  • 4,348
  • 14
  • 46
  • 70

1 Answers1

2

Pass the array by reference

function scan_image(&$arr,$root){
Musa
  • 96,336
  • 17
  • 118
  • 137