Re: Appending into associative arrays

From: Date: Mon, 16 Apr 2007 22:13:37 +0000
Subject: Re: Appending into associative arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-253063@lists.php.net to get a copy of this message
On Sun, April 15, 2007 2:20 pm, Otto Wyss wrote: > 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? Two files may have the same modification time. You are storing only ONE file for any given timestamp. You could do something like this: foreach($files as $file){ $dirs[filemtime($file)][] = $file; } You will then have an ARRAY for each timestamp with all the files that were modified at that time. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#253063) next »