array sorting question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

array sorting question.

Post by kingconnections »

OK so i have an array that I added a value too. It currently looks like these print_r results:

Array ( [ABRF] => Array ( [MS06-007] => Array ( [0] => 1 ) [MS06-008] => Array ( [0] => 1 ) [MS06-001] => Array ( [0] => 0 ) )
[ADRF] => Array ( [MS06-001] => Array ( [0] => 1 ) [MS06-007] => Array ( [0] => 1 ) [MS06-008] => Array ( [0] => 1 ) )


Notice that in the 1st row it goes ABRF, MS06-007,MS06-008,MS06-001
and the 2nd row it is -------------- ADRF, MS06-001,MS06-007,MS06-008

I need every record to be sorted in the same order as the second result.

Here is what I currently have been trying:

Code: Select all

foreach ($site_array as $site_key => $site_val) 

{ 

 foreach ($site_val as $site_name => $site_data) 
 {
ksort($site_name);

echo "$site_val------$site_key--------$site_name<br>";       
         
 }   //2nd dimension          
                    
} // 1st dimension
ryos
Forum Newbie
Posts: 16
Joined: Tue Feb 14, 2006 4:55 pm

Post by ryos »

The ksort function takes the array to be sorted as a parameter. It looks like you're passing it a key. Try:

Code: Select all

foreach ($site_array as $site_val)  {
     ksort ($site_val);
}
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

I fixed it. I did not end up using a sort. What I did was , I prepopulated the array before I ran my sql query.


Thanks

Dan
Post Reply