View Single Post
drewprops
Space Pirate
 
Join Date: May 2004
Location: Atlanta
 
2005-01-30, 23:23

Okay.
I understand the beginner's lessons on ways to create multidimensional arrays, but I'm not as certain how to fill a multidimensional array with other arrays by using a looping statement (while/if). I've been playing with this for the last few hours but have yet to get it to work and know that I'm missing a simple step in loading the array. What am I doing wrong?

Here's an example:
Let's say that I have a simple array called $filename that has been populated with ten JPEG files' names. I want to refine my control of these files and categorize them by the first four characters of each file, so I create a loop and cycle through the contents of $filename and use it to help name elements in the multidimensional array...

Code:
$filename=array('arch_001.jpg','arch_002.jpg','arch_003.jpg','logo_001.jpg', 'logo_002.jpg','iden_001.jpg','clad_001.jpg','clad_002.jpg','firt_001.jpg','firt_002.jpg'); $countup=10; if ($i=0;$i<$countup;$i++){ $filecategory=substr($filename[$i],0,4);//grab the first four characters of the filename $filecat[$filecategory][$i]=$filename[$i];//stick into a multi-dimensional array using its category }

Steve Jobs ate my cat's watermelon.
Captain Drew on Twitter
  quote