简体   繁体   English

PHP Glob不返回所有/ any文件

[英]PHP Glob not returning all /any files

I'm on a WIN 10 machine. 我在WIN 10机器上。 Doing a small PHP script for my own use (not to upload). 做一个小的PHP脚本供我自己使用(不上传)。

My code is: 我的代码是:

    echo getcwd() . "<br />\n";
    $files=glob("*.txt");
    $log=1;
    krsort($files);
    reset($files);
    foreach($files as $ab => $ac);
    {
    $ac=trim($ac);
    echo "'$ab' '$ac'<br />\n";
    $got=trim($ac);
    }

the directory path is correct, however it returns ONE file (there are 3 x txt files in the directory). 目录路径正确,但是返回一个文件(目录中有3 x txt文件)。

i changed it to the following which should show up all the files - including the PHP scripts, but it still only shows 1 file & then stop. 我将其更改为以下内容,应显示所有文件-包括PHP脚本,但仍仅显示1个文件,然后停止。

     glob("*.*") 

Is there something dumb i'm doing wrong - why isnt it globbing all the files (or all txt files) ? 我做错什么了吗-为什么不遍历所有文件(或所有txt文件)?

EDIT - PHP Version 7.1.9 编辑-PHP版本7.1.9

SOLVED. 解决了。

It was:- 它是:-

     foreach($files as $ab => $ac);
     {

It should be 它应该是

    foreach($files as $ab => $ac)
    {

I found the answer here :- 我在这里找到答案:-

Foreach only showing last item in array Foreach仅显示数组中的最后一项

I dont know WHY it does, but the un-needed semicolon only displays 1 value/key of an array. 我不知道为什么会这样,但是不需要的分号仅显示数组的1个值/键。

(i need better eyes), but i guess other folk didnt see it either. (我需要更好的眼睛),但是我想其他人也没有看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM