View Single Post
Gargoyle
http://ga.rgoyle.com
 
Join Date: May 2004
Location: In your dock hiding behind your finder icon!
 
2005-02-01, 07:57

Foreach is the king of processing arrays. Try this on for size...

[php]
$filename=array(
'arch_001.jpg', 'arch_002.jpg', 'arc h_003.jpg',
'logo_001.jpg', 'logo_002.jpg', 'iden_001.jpg',
'clad_001.jpg', 'clad_002.jpg', 'firt_001.jpg',
'firt_002.jpg'
);

foreach ($filename as $key => $value) {
$filecategory=substr($value, 0, 4); // Get category.
$filecat[$filecategory][] = $value;
}

[/php]


You dont need this counter anymore.
Code:
$countup=10;
using empty [] pushes your value onto the end of the array. If you want to preserve the original index use $filecat[$filecategory][$key] = $value instead.

Enjoy

Edit: Eeee the orange in the php code comments looks nasty, moved them out of the code section. Brad....

OK, I have given up keeping this sig up to date. Lets just say I'm the guy that installs every latest version as soon as its available!
  quote