RE: Going loopy with arrays.....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
that's a dump of the array....can you paste the source?
[/snip]

Not really. The original array was manipulated to get the point (H)
groups together for the new array so that I could break the points back
out together (they are not together in the original file). Here is how I
got there....

A sample of the text file (someone else providing);

"H7"	-99.2117	29.087
"H7"	-99.2146	29.087
"H7"	-99.1864	29.1026
"H7"	-99.1807	29.0837
"H7"	-99.1668	29.0619
"H6"	-99.0876	29.216
"H6"	-99.0618	29.179
"H6"	-99.0699	29.1652
"H6"	-99.0699	29.166
"H6"	-99.0761	29.1765
"H6"	-99.0761	29.1879
"H6"	-99.0752	29.1895
"H6"	-99.102	29.2353
"H6"	-99.1293	29.2503
"H6"	-99.1288	29.2524
"H6"	-99.1264	29.2738
"H6"	-99.124	29.2764
"H6"	-99.1078	29.281
"H6"	-99.1063	29.2806
"H6"	-99.0901	29.2642
"H6"	-99.0881	29.2642
"H6"	-99.0762	29.2684
"H6"	-99.069	29.2785
"H6"	-99.0685	29.2793
"H6"	-99.0647	29.2806

$mapFile3 = fopen("inc/Outdoor_HolesH1-H7.txt", "r");

$op = 0;
while(!feof($mapFile3)){
	$mapLine = fgets($mapFile3, 4096);
	if("" != $mapLine){
		$mapLineArr = explode("\t", $mapLine);
		$mapArray3[$op]['id'] = str_replace("\"",
"",$mapLineArr[0]);
		$mapArray3[$op]['lon'] =
$mapLineArr[count($mapLineArr)-2];
		$mapArray3[$op]['lat'] =
$mapLineArr[count($mapLineArr)-1];
		$op++;
	}
}
fclose($mapFile3);

function groupByFirst($array)
{
   foreach ($array as $row)
   {
       $firstKey = array_keys($row);
       $firstKey = $firstKey[0];
       $key = $row[$firstKey];
       unset($row[$firstKey]);
       $newArray[$key][] = $row;
   }
   return $newArray;
}


$new = groupByFirst($mapArray3);

print_r($new); 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux