homer.favenir Posted May 16, 2008 Share Posted May 16, 2008 hi to all, can anyone please tell me how to sort variable? ??? this is my script <?php echo '<pre>'; $lines = file("SC29120_zc.txt"); $count = 0; foreach($lines as $line) { $words = substr($line, 143, 243) . "<br>"; list($strno, $strname) = explode(" ", $words, 2); if(preg_match("/[0-9]/", $strno)) { echo "line " . $count . " #: " . $strno; echo " Name: " . $strname . "<br>"; } $count++; } echo '<pre>'.$count.'</pre>'; echo '</pre>'; ?> output: line 2 #: 1307 Name: MILSTEAD AV N*E CNYRS 30012770 922-5939V2 line 3 #: 10258 Name: FLAT SHOALS RD COVINGTON 30014770 786-1531V2 line 11 #: 3114 Name: MERCER UNIVERSITY DR CHAMBLEE 30341770 454-8080V2 line 16 #: 3336 Name: SPRING CREEK DR CNYRS 30013770 483-6506V2 line 18 #: 620 Name: SIGMAN RD N*E CNYRS 30013770 922-6720V2 line 19 #: 4715 Name: RALEIGH CT S*E CNYRS 30094770 760-1233V2 line 21 #: 6125 Name: HIGHWAY 36 COVI 30014770 788-1331V2 line 22 #: 1229-F Name: ROYAL DR S*W CNYRS 30094770 483-6136V2 line 23 #: 1050 Name: GREEN ST S*W CNYRS 30012770 929-0349V2 line 24 #: 1114 Name: CLARK ST N*W COV 770 787-1667V2 line 25 #: 10255 Name: INDUSTRIAL BLVD COV 30014770 784-7663V2 line 26 #: 1267 Name: PARKER RD S*W CNYRS 770 922-1166V2 line 27 #: 938 Name: CENTER ST NW CNYRS 770 483-3878V2 line 28 #: 954 Name: S MAIN ST N*E CNYRS 30012770 929-3552V2 line 29 #: 25 Name: FLINT HILL DR OXFORD 30054770 787-3244V2 line 30 #: 3157 Name: MILL ST N*E COVINGTON 30014770 787-5897V2 line 31 #: 6156 Name: GORDY ST N*E 30014770 786-4810V2 line 32 #: 1264 Name: PARKER RD S*E CNYRS 30094770 922-1040V2 i need to order by $strname, $strno. can anyone please..... thanks Link to comment https://forums.phpfreaks.com/topic/105876-sorting-variables/ Share on other sites More sharing options...
cooldude832 Posted May 16, 2008 Share Posted May 16, 2008 sounds like you should have this data in a database if you are going to use it more than once. Are u using it more than once? Link to comment https://forums.phpfreaks.com/topic/105876-sorting-variables/#findComment-542595 Share on other sites More sharing options...
homer.favenir Posted May 16, 2008 Author Share Posted May 16, 2008 just once sir Link to comment https://forums.phpfreaks.com/topic/105876-sorting-variables/#findComment-542596 Share on other sites More sharing options...
cooldude832 Posted May 16, 2008 Share Posted May 16, 2008 what you are going to need to do is build a sorting function it involves takes the array u have and then building a second array with the "sorts" which in your case is going to be bits of the whole array node i.e a node is line 2 #: 1307 Name: MILSTEAD AV N*E CNYRS 30012770 922-5939V2 the sort for "line 2" is "MILSTEAD AV N*E 1307" this will help explain this cause i'm not very good at doing user sort functions http://us3.php.net/manual/en/function.usort.php Link to comment https://forums.phpfreaks.com/topic/105876-sorting-variables/#findComment-542599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.