JBS103 Posted February 17, 2007 Share Posted February 17, 2007 I have another quick question. I have a simple setup like so: <?php $aNumber = array(1, 1, 2); $bNumber = array_unique($aNumber); ?> This works perfectly, however, print_r creates: Array ( [0] => 1 [2] => 2 ) Is there a built in function that I can use to make it: Array ( [0] => 1 [1] => 2 ) Or do I need to write my own conditional to reset the array values? I simplified this greatly; when I actually implement it, the array could be 30 elements long with 10 repeats. All values would be numbers however. So I need some sort of function. Thanks. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 you could use sort which will reorder them with new keys. Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks, I didn't know sort would re-key them. Quote Link to comment Share on other sites More sharing options...
flaab Posted February 24, 2007 Share Posted February 24, 2007 Hello =) I have the same...an array like this... array = ["name1", "name2", "name1", "name2"]; I did an array_unique and then i want the keys to be consistent. But sort its not working. How should i do it? Thanks., Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 24, 2007 Author Share Posted February 24, 2007 Make sure your syntax is correct. Something like this should work. $arrayVar = array("name1", "name1", "name2", "name2"); $arrayVar = array_unique($arrayVar); 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.