stinkbug Posted March 21, 2008 Share Posted March 21, 2008 I'm a php newbie so this might be a stupid question, but..... I'm dealing with an array that has key names that are not useful to me. The key names are based on the values they point to so they are always changing. I'm unable to change the function that creates the array. Ideally I'd like to refer to the array variables by index number (i.e. $stupidArray[0]). My solution was to implode the array into a string and then turn that string into a new array. It seems to work. But is there a cleaner way of doing that? I see that there are functions to do all sorts of things to keys, but I didn't see a method for just clearing out the key names and replacing them with index numbers. I suppose there's probably some super simple way of doing this but I'm still in my earlier php/programming stage so I'm clueless half the time. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/97195-how-do-i-strip-out-key-values-names/ Share on other sites More sharing options...
sKunKbad Posted March 21, 2008 Share Posted March 21, 2008 foreach ($oldArray as $key => $value){ $newArray[] = $value; } Quote Link to comment https://forums.phpfreaks.com/topic/97195-how-do-i-strip-out-key-values-names/#findComment-497346 Share on other sites More sharing options...
Barand Posted March 21, 2008 Share Posted March 21, 2008 $new_array = array_values ($old_array); Quote Link to comment https://forums.phpfreaks.com/topic/97195-how-do-i-strip-out-key-values-names/#findComment-497414 Share on other sites More sharing options...
stinkbug Posted March 23, 2008 Author Share Posted March 23, 2008 thank you! that worked great! you guys rock almost as much as php! Quote Link to comment https://forums.phpfreaks.com/topic/97195-how-do-i-strip-out-key-values-names/#findComment-498673 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.