Page 1 of 1

array sorting question.

Posted: Thu Feb 23, 2006 3:44 pm
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

Posted: Thu Feb 23, 2006 7:39 pm
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);
}

Posted: Fri Feb 24, 2006 11:21 am
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