Jump to content

Simple sorting problem


aashcool198

Recommended Posts

I have two arrays.. one of firstname $arr_f[]  and other is of lastname $arr_l[]...

i am displaying the full name as..

 

for($i=0; $i<10; $i++){

 

echo $arr_f[].$arr_l[];

 

}

 

 

But displayed names are orderless. if i sort $arr_f[] then how will i make sure that firstname and lastname are correctly displayed together.

 

Please Help!

Link to comment
https://forums.phpfreaks.com/topic/163247-simple-sorting-problem/
Share on other sites

combine your list like so: (assumes count($arr_f)==count($arr_l))

 

for($i=0;$i<count($arr_f);++$i) {
  $names[$arr_f[$i]]=$arr_l[$i];
}

 

Then you can use asort() or ksort() to order your list and finally

 

foreach($names as $first=>$last) {
  echo $first.$last;
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.