FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » count() problem
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
count() problem [message #185705] Sat, 03 May 2014 18:18 Go to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
$dir = '../audio/'.$yr.'/';
$files = scandir($dir);
$number=count(files);
echo $number;

Why does this always show the resutlt as 1?


$dir = '../audio/'.$yr.'/';
$files = scandir($dir);
echo count(files);

Shows the true count of the array.
Re: count() problem [message #185706 is a reply to message #185705] Sat, 03 May 2014 18:32 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 03.05.2014 20:18, schrieb richard:
>
> $dir = '../audio/'.$yr.'/';
> $files = scandir($dir);
> $number=count(files);
did you mean
$number=count($files);
?
/Str.
> echo $number;
>
> Why does this always show the resutlt as 1?
>
>
> $dir = '../audio/'.$yr.'/';
> $files = scandir($dir);
> echo count(files);
>
> Shows the true count of the array.
>
Re: count() problem [message #185707 is a reply to message #185705] Sat, 03 May 2014 18:33 Go to previous messageGo to next message
Richard Yates is currently offline  Richard Yates
Messages: 86
Registered: September 2013
Karma: 0
Member
On Sat, 3 May 2014 14:18:22 -0400, richard <noreply(at)example(dot)com>
wrote:

>
> $dir = '../audio/'.$yr.'/';
> $files = scandir($dir);
> $number=count(files);
> echo $number;
>
> Why does this always show the resutlt as 1?

Because you left out a '$'
Re: count() problem [message #185708 is a reply to message #185705] Sat, 03 May 2014 18:36 Go to previous messageGo to next message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma: 0
Senior Member
Am 03.05.2014 20:18, schrieb richard:
>
> $dir = '../audio/'.$yr.'/';
> $files = scandir($dir);
> $number=count(files);
> echo $number;
>
> Why does this always show the resutlt as 1?
>
>
> $dir = '../audio/'.$yr.'/';
> $files = scandir($dir);
> echo count(files);
>
> Shows the true count of the array.
>
And you still have turned error reporting off. How often have you been told to turn
it on?

php > echo count(files), "\n";
PHP Notice: Use of undefined constant files - assumed 'files' in php shell code on
line 1

Notice: Use of undefined constant files - assumed 'files' in php shell code on line 1
1
php >

/Str.
Re: count() problem [message #185709 is a reply to message #185706] Sat, 03 May 2014 19:57 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Sat, 03 May 2014 20:32:56 +0200, M. Strobel wrote:

> Am 03.05.2014 20:18, schrieb richard:
>>
>> $dir = '../audio/'.$yr.'/';
>> $files = scandir($dir);
>> $number=count(files);
> did you mean
> $number=count($files);
> ?
> /Str.
>> echo $number;
>>
>> Why does this always show the resutlt as 1?
>>
>>
>> $dir = '../audio/'.$yr.'/';
>> $files = scandir($dir);
>> echo count(files);
>>
>> Shows the true count of the array.
>>

thanks. many times I overlook the obvious.
Re: count() problem [message #185712 is a reply to message #185709] Sat, 03 May 2014 22:14 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Sat, 03 May 2014 15:57:26 -0400, richard wrote:

> On Sat, 03 May 2014 20:32:56 +0200, M. Strobel wrote:
>
>> Am 03.05.2014 20:18, schrieb richard:
>>>
>>> $dir = '../audio/'.$yr.'/';
>>> $files = scandir($dir); $number=count(files);
>> did you mean
>> $number=count($files);
>> ?
>> /Str.
>>> echo $number;
>>>
>>> Why does this always show the resutlt as 1?
>>>
>>>
>>> $dir = '../audio/'.$yr.'/';
>>> $files = scandir($dir);
>>> echo count(files);
>>>
>>> Shows the true count of the array.

> thanks. many times I overlook the obvious.

Did you even think to check for any warning messages? Did you have
warnings turned on? PHP will usually generate a warning if warnings are
on and you appear to have left a $ off of a variable name.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: scandir problem
Next Topic: how to join two arrays?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 11:29:02 GMT 2024

Total time taken to generate the page: 0.02585 seconds