galvin Posted May 8, 2009 Share Posted May 8, 2009 If you have this array... var animals = new Array("cat*","dog*","monkey","whale*","emu","llama*") ....How can you make a new array of ONLY the elements in the first array that end in an asterisk? So the new array would be.. ("cat*","dog*","whale*","llama*") Again, how do you extract just the ones that end in an asterisk and put them in a new array? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/157306-solved-how-to-remove-certain-array-elments-and-put-them-in-a-new-array/ Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Loop through them, check if it ends in a *, then add it to a new array. Otherwise, go to the next entry. Quote Link to comment https://forums.phpfreaks.com/topic/157306-solved-how-to-remove-certain-array-elments-and-put-them-in-a-new-array/#findComment-829161 Share on other sites More sharing options...
galvin Posted May 8, 2009 Author Share Posted May 8, 2009 Thanks...can you tell me what function to use to check to see if an array element ends with a certain character (in this case, an asterisk)? Quote Link to comment https://forums.phpfreaks.com/topic/157306-solved-how-to-remove-certain-array-elments-and-put-them-in-a-new-array/#findComment-829374 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 You can just use Regex. Quote Link to comment https://forums.phpfreaks.com/topic/157306-solved-how-to-remove-certain-array-elments-and-put-them-in-a-new-array/#findComment-829435 Share on other sites More sharing options...
galvin Posted May 8, 2009 Author Share Posted May 8, 2009 thanks Quote Link to comment https://forums.phpfreaks.com/topic/157306-solved-how-to-remove-certain-array-elments-and-put-them-in-a-new-array/#findComment-829549 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.