Re: Array Sorting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



James Nunnerley wrote:

I think I may have written down my variable structure incorrectly in the
first place, which even has me confused...

The $file_array[$filename] is I don't think a further array.

The "sub" values are created as follows:
$file_array[$filename]["Date"] = ... $file_array[$filename]["Size"] = ...

Looking at usort, it will put the list of Dates in order (by doing a pure if
is bigger or smaller...) but will loose the link between the particular
filename and it's date properties.

Does that make sense - or am I loosing the plot?

That is indeed what it will do. If that's a problem you probably also want to define a "Filename" element for each item...

$file_array[$filename]["Filename"] = $filename;

It's worth noting that if you're not using the fact that they're indexed on the filename it's probably faster to use integer keys instead of strings, but don't quote me on that. I'm not overly familiar with the internals of PHP... yet!

Am I also making a mistake by not defining $file_array[$filename]?  I don't
think so, but would be happy to be corrected!

PHP is quite relaxed about these things, but from syntactic(?) completeness and security points of view it should really be initialised to an empty array.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux