Cannot Redeclare Function

From: Date: Thu, 19 Sep 2002 15:58:09 +0000
Subject: Cannot Redeclare Function
Groups: php.general 
Request: Send a blank email to php-general+get-116896@lists.php.net to get a copy of this message
Hello, My function to read a comma separated text file and return a sorted multi-dimensional array will not work if used more than once per page. I know why I'm having this problem. But, I don't know how to solve it. :-( Calling it Twice: $services = tbl2array ("../locations/service.txt", "default", $divdetail['id'], "0"); $collections = tbl2array ("../download/collection.txt", "name", $divdetail['id'], "4"); The Error: Fatal error: Cannot redeclare compname() in ../tbl2array.inc on line 35 Function Table 2 Array: <?php function tbl2array ($table, $sortby = "default", $keyword = "all", $keyfield = "0") { $fpointer = fopen ($table,"r"); $row = 1; $leaf = array(); $heading = array(); while ($data = fgetcsv ($fpointer,1000)) { if ($row == 1) { $heading = $data; } else { $count = 0; if ($keyword == "all") { foreach ($data as $value) { $leaf[$heading[$count]] = $value; $count++; } $result[] = $leaf; } elseif (($keyword != "all") && ($data[$keyfield] == $keyword)) { foreach ($data as $value) { $leaf[$heading[$count]] = $value; $count++; } $result[] = $leaf; } else { $count++; } } $row++; } fclose ($fpointer); function compname ($a, $b) { return strcmp ($a["name"], $b["name"]); } function comptitle ($a, $b) { return strcmp ($a["title"], $b["title"]); } function compcity ($a, $b) { return strcmp ($a["city"], $b["city"]); } function compdesc ($a, $b) { return strcmp ($a["description"], $b["description"]); } function compfile ($a, $b) { return strcmp ($a["filename"], $b["filename"]); } if ($sortby == "name") { usort ($result, "compname"); } elseif ($sortby == "title") { usort ($result, "comptitle"); } elseif ($sortby == "city") { usort ($result, "compcity"); } elseif ($sortby == "description") { usort ($result, "compdesc"); } elseif ($sortby == "filename") { usort ($result, "compfile"); } return $result; } ?> ---------------------------------------------------------------------- Robert J. Miller Internet Support Specialist Department of Government Services and Lands P.O. Box 8700, St. John's, NF., A1B-4J6 (709) 729-4520 (phone) (709) 729-4151 (facsimile) (709) 778-8746 (pager) http://www.gov.nf.ca/gsl/ mailto:rmiller@gov.nf.ca ---------------------------------------------------------------------- Simple things should be simple and hard things should be possible. ----------------------------------------------------------------------

« previous php.general (#116896) next »