开发者

Fill up an array IF statement

<?php 
if ($handle = opendir('gallery3/var/thumbs/Captain-America/')) { 
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != "..") { 
            echo "$file\n";?><br/><开发者_开发知识库? 
            echo rtrim($file, '.jpg');?><br/><?
            $names[]=$file;
        } 
    } 
    closedir($handle);
}    
?>

I want to createa an array of the file names that are outputting and also the rtrim elements.


glob (coupled with array_map) may do a better job, but you can create an array, and add matches to it very simply:

$files = array(); // declare
...
$files[] = rtrim($file,'.jpg'); // adding entry
...
print_r($files); // debug output to see it

The glob example:

// with or without the array_map to basename()
$files = array_map('basename',glob('gallery3/var/thumbs/Captain-America/*'));
var_dump($files); // normal files

$files_rtrim = array_map(create_function('$f','return rtrim($f,".jpg");'),$files);
var_dump($files_rtrim); // rtrim version of same files
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜