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. Quote Link to comment Share on other sites More sharing options...
waynewex 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 ?> Quote Link to comment 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)? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.