Re: Appending into associative arrays

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

 



$fmtime = filemtime($d);
if (!array_key_exists($fm,$dir)) $dir[$fm] = array();
$dir[$fm][] = $d;

This would give you an array indexed by filetime containing arrays of filenames. You may try and see if the last line is enough on its own, but I believe it once happened to me that it failed to create a two levels deep array of arrays in just one shot, that's why the second line. Alternatively you could use the filename as key of the second array and store in it any information as data, for whatever you might need:

$dir[$fm][$d] = some data related to $d.

Satyam


----- Original Message ----- From: "Otto Wyss" <otto.wyss@xxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Sunday, April 15, 2007 9:20 PM
Subject:  Appending into associative arrays


I want to sort directories according there modification time and thought accociative arrays would be perfect. But when I add an element like

$dirs = array (filemtime($d) => $d)

the previous ones are lost. I tried array_push but that doesn't seems to work, at least I always get syntax errors. Next try was array_merge(array (...)). So what next?

O. Wyss

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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.4.0/761 - Release Date: 14/04/2007 21:36



--
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