holowugz Posted May 27, 2008 Share Posted May 27, 2008 Hi guys here is what i am looking to do, the user dumps a large amount of text into a text box, and submits it here is an example of a line of the text: 2008-04-19 00:01:31: 67.71.153.73 Spud [?] Basically date, time, IP, Username I need these to be resorted to display by date and time. //if user presses submit button if($_POST['Submit']=="Submit"){ //Remove whitespace from beginning and end, and remove the [?] from the text $_POST['textarea']= trim(str_ireplace(" [?] ","",$_POST['textarea'])); //insert into array, seperated by new line $alpha=explode("\n",$_POST['textarea']); $counter = 0; //for every element in the array put it into array cheese (creating multi dimensional array) foreach ($alpha as $value) { $cheese["$counter"]=explode(" ",$value); $counter++; } echo "</br>"; //sort array by date and then time array_multisort($cheese[0],SORT_ASC,SORT_REGULAR,$cheese[1],SORT_ASC,SORT_REGULAR); //debug function, remove before final release var_dump($cheese); echo "</br>"; echo "<table width=\"50%\" border=\"1\"> <tr> <td>Date</td> <td>Time</td> <td>IP</td> <td>Name</td> </tr>"; foreach ($cheese as $value) { echo " <tr> <td>$value[0]</td> <td>$value[1]</td> <td>$value[2]</td> <td>$value[3]</td> </tr>"; } echo "</table>"; } The problem is it will NOT sort correctly i just get a jumbled mess, can anyone help? Link to comment https://forums.phpfreaks.com/topic/107388-sorting-a-multi-dimensional-array/ Share on other sites More sharing options...
mushroom Posted May 27, 2008 Share Posted May 27, 2008 The way I have handled this in the past is to convert them to a simple array with an "/" as a separator $x=0; # start loop1 $new_array1[]="$time..../$ip.../$data.../$etc...."; $x++; # end loop1 sort($new_array1); $x=0; # start loop2 $new_array2=explode("/",$new_array1[$x]); # use the new array or put it back sorted $x++; # end loop2 Link to comment https://forums.phpfreaks.com/topic/107388-sorting-a-multi-dimensional-array/#findComment-550572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.