I’ve written a bunch of program over the years, but only recently started using PHP. I’m currently converting some ancient QuickBASIC educational programs so they can be Web-accessible. Here’s the problem:
I have a flat file of animals and genetic traits. The following is a sample:
[CODE]hamsters1
brown eyes
blue eyes
pink eyes
smooth hair
rough hair
broken hair
golden hair
black hair
large ears
small ears
The file continues on like the above. There are six different animal species, four sets of each species and 10 traits for each species.
I tried a somewhat direct translation of the QuickBASIC to PHP, but it doesn’t work:
[CODE]$file = fopen(“allanims.txt”, “r”);
for ($i = 1; $i <= 6; $i++) {
for ($j = 1; $j <= 4; $j++) {
$species[$i][$j] = fgets($file);
for ($k = 1; $k <= 10; $k++) {
$trait[$i][$j][$k] = fgets($file);
}}}
fclose($file);
I’ve read a lot of stuff about multi-dimensional arrays in PHP, but all the examples involve hard coding the array contents, rather than reading them from a file.
Lane