kaveman50 Posted November 10, 2009 Share Posted November 10, 2009 Hello does anyone know how to solve this? Accept 5 words to be input in alphabetical order and store them in an array (If input out of alphabetical order, write your script to fix it). Then accept a 6th word as input and store it in the array in its correct alphabetical position. Link to comment https://forums.phpfreaks.com/topic/181007-search-and-sort/ Share on other sites More sharing options...
waynew Posted November 10, 2009 Share Posted November 10, 2009 <?php $out_of_order = array("Wayne", "Apples", "Car", "Building", "Zebra"); sort($out_of_order); //will sort the array into alphabetical order $new_var = "Penguin"; array_push($out_of_order,$new_var); //place variable in array sort($out_of_order); //sort array ?> Link to comment https://forums.phpfreaks.com/topic/181007-search-and-sort/#findComment-954976 Share on other sites More sharing options...
Adam Posted November 10, 2009 Share Posted November 10, 2009 Seems the middle step is a little pointless. Couldn't you just cut it out altogether and sort the array after you've pushed the 6th word (OP)? Link to comment https://forums.phpfreaks.com/topic/181007-search-and-sort/#findComment-954978 Share on other sites More sharing options...
kaveman50 Posted November 10, 2009 Author Share Posted November 10, 2009 It can't have names already in the code because the user has to enter the names. Link to comment https://forums.phpfreaks.com/topic/181007-search-and-sort/#findComment-954979 Share on other sites More sharing options...
Adam Posted November 10, 2009 Share Posted November 10, 2009 Well with wayne's solution you could just populate that array from text inputs, push the 6th word and then sort the array? Forgive me if I'm wrong but is this some kind of home work? Link to comment https://forums.phpfreaks.com/topic/181007-search-and-sort/#findComment-954980 Share on other sites More sharing options...
kaveman50 Posted November 10, 2009 Author Share Posted November 10, 2009 Nah it's not homework but I figured it out. Thanks guys Link to comment https://forums.phpfreaks.com/topic/181007-search-and-sort/#findComment-954981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.