Re: solved [message #185731 is a reply to message #185730] |
Mon, 05 May 2014 13:51 |
Christoph Michael Bec
Messages: 207 Registered: June 2013
Karma:
|
Senior Member |
|
|
richard wrote:
> On Mon, 05 May 2014 11:11:35 +0100, Ben Bacarisse wrote:
>
>> richard <noreply(at)example(dot)com> writes:
>>
>>> On Sun, 04 May 2014 22:27:01 -0400, Jerry Stuckle wrote:
>> <snip>
>>>> But you didn't show your entire code, so it's hard to say what could be
>>>> wrong.
>>>
>>> for ($x=0;$x<=$number;$x++){
>>>
>>> if ($files[x] !=".") {
>> ^ not $x
>>
>>> $master[$lo]=$files[$x];
>>> $lo=$lo+1;
>>> }
>>> }
>>
>> You really need to find some what to work which lets you see all the
>> notices and warnings that PHP can give you.
>>
>> By the way, writing $master[] = ... puts an element at the next unused
>> numerical index in the array which might be what you are doing here with
>> $lo. I'd write the above like this:
>>
>> foreach ($files as $file)
>> if ($file !== '.')
>> $master[] = $file;
>
> Thanks. Works like a charm.
> Now how do I also include the ".."?
> foreach ($files as $file)
> if ($file !== '.' || $file!=="..")
> $master[] = $file;
> This does not seem to work.
I assume that it does what it should: it will append any file whose name
is not equal to '.' *or* not equal to '..', i.e. every file. You want
to use the && operator here.
Another option which excludes all hidden files:
if ($file[0] != '.')
> Time to implement the formidable goto eh?
Fortunately not.
--
Christoph M. Becker
|
|
|