Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12074
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: sorting readdir output? |
| Date | 2013-12-02 20:24 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <l7iqam$7ms$4@dont-email.me> (permalink) |
| References | <1g1k8whk9o5qm.19jj117exjuzm.dlg@40tude.net> <4olp991cbd375tc26o1al9l9cnpjoc3jpp@4ax.com> |
On Mon, 02 Dec 2013 10:54:49 -0800, Richard Yates wrote:
> On Sun, 1 Dec 2013 11:39:20 -0500, richard <noreply@example.com>
> wrote:
>
> Isn't "false !==" unnecessary?
>
>><?php
>>
>>if ($handle = opendir('../audio/1960/')) {
>> echo "Directory handle: $handle\n";
>> echo "Entries:\n";
>>
>> /* This is the correct way to loop over the directory. */
>> while (false !== ($entry = readdir($handle))) {
>> echo "$entry\n<br>";
>> }
>>
>> closedir($handle);
>>}
>>?>
>>
>>This gives the output in an unsorted list.
>>How can I make it so the array is sorted?
>>
>>http://us1.php.net/readdir
1. Please post replies *BELOW* the points they address, this is usenet,
we've been reading from down the page for years now and it's the way we'd
like to continue doing it.
2. Your question could be easily answered by reading the relevant manual
entry for the function concerned. Possibly much faster than by posting to
usenet and waiting for a response. Perhaps you should try that next time?
3. Said manual entry ( http://www.php.net/manual/en/function.readdir.php
) contains:
"Return Values
Returns the entry name on success or FALSE on failure.
Warning
This function may return Boolean FALSE, but may also return a non-Boolean
value which evaluates to FALSE. Please read the section on Booleans for
more information. Use the === operator for testing the return value of
this function."
See: http://www.php.net/manual/en/language.types.boolean.php
Which includes:
"Converting to boolean
To explicitly convert a value to boolean, use the (bool) or (boolean)
casts. However, in most cases the cast is unnecessary, since a value will
be automatically converted if an operator, function or control structure
requires a boolean argument.
See also Type Juggling.
When converting to boolean, the following values are considered FALSE:
the boolean FALSE itself
the integer 0 (zero)
the float 0.0 (zero)
the empty string, and the string "0" <----------------------****
an array with zero elements
an object with zero member variables (PHP 4 only)
the special type NULL (including unset variables)
SimpleXML objects created from empty tags
Every other value is considered TRUE (including any resource)."
So yes, "false !==" is needed, because you can have a valid result which
would evaluate to false (such as the valid file name "0").
--
Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sorting readdir output? richard <noreply@example.com> - 2013-12-01 11:39 -0500
Re: sorting readdir output? Norman Peelman <npeelman@cfl.rr.com> - 2013-12-01 11:56 -0500
Re: sorting readdir output? richard <noreply@example.com> - 2013-12-01 12:13 -0500
Re: sorting readdir output? Luuk <luuk@invalid.lan> - 2013-12-01 18:32 +0100
Re: sorting readdir output? Luuk <luuk@invalid.lan> - 2013-12-01 18:35 +0100
Re: sorting readdir output? richard <noreply@example.com> - 2013-12-01 13:10 -0500
Re: sorting readdir output? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2013-12-01 13:19 -0500
Re: sorting readdir output? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2013-12-01 12:59 -0500
Re: sorting readdir output? "James Harris" <james.harris.1@gmail.com> - 2013-12-01 18:10 +0000
Re: sorting readdir output? richard <noreply@example.com> - 2013-12-01 13:19 -0500
Re: sorting readdir output? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-01 23:41 +0000
Re: sorting readdir output? Richard Yates <richard@yatesguitar.com> - 2013-12-02 10:54 -0800
Re: sorting readdir output? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-02 20:24 +0000
Re: sorting readdir output? Richard Yates <richard@yatesguitar.com> - 2013-12-02 13:02 -0800
Re: sorting readdir output? Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-02 22:33 +0100
Re: sorting readdir output? Tim Streater <timstreater@greenbee.net> - 2013-12-02 22:20 +0000
Re: sorting readdir output? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-02 23:54 +0000
csiph-web