xiao Posted May 17, 2008 Share Posted May 17, 2008 Is there a way to turn an array like this Array ( [somename] => Cat [someothername] => Bird [anothername] => Horse ) into Array ( [0] => Cat [1] => Bird [2] => Horse ) ? Quote Link to comment https://forums.phpfreaks.com/topic/106057-array-problem/ Share on other sites More sharing options...
ShimmyShine Posted May 17, 2008 Share Posted May 17, 2008 Could be this: array(0 => 'Cat', 1 => 'Bird', 2 => 'Horse'); That should fix your problem. Shimmy Quote Link to comment https://forums.phpfreaks.com/topic/106057-array-problem/#findComment-543517 Share on other sites More sharing options...
xiao Posted May 17, 2008 Author Share Posted May 17, 2008 yea, but the problem is that I already have the array with all the names and I need to transform it. Quote Link to comment https://forums.phpfreaks.com/topic/106057-array-problem/#findComment-543522 Share on other sites More sharing options...
ShimmyShine Posted May 17, 2008 Share Posted May 17, 2008 I don't understand what you are looking for, transform it how? Why not use it the way it is? Shimmy Quote Link to comment https://forums.phpfreaks.com/topic/106057-array-problem/#findComment-543525 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2008 Share Posted May 17, 2008 Do this: <?php $old_array = Array ( 'somename' => 'Cat', 'someothername' => 'Bird', 'anothername' => 'Horse' ); $new_array = array(); foreach ($old_array as $v) $new_array[] = $v; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/106057-array-problem/#findComment-543703 Share on other sites More sharing options...
wildteen88 Posted May 17, 2008 Share Posted May 17, 2008 As an additional note to kens suggestion you could just use the array_values() function. $old_array = Array ( 'somename' => 'Cat', 'someothername' => 'Bird', 'anothername' => 'Horse' ); $new_array = array_values($old_array); Quote Link to comment https://forums.phpfreaks.com/topic/106057-array-problem/#findComment-543738 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.