k0z Posted September 7, 2009 Share Posted September 7, 2009 Hi, This is my current code: <?php $favorites=2; $recent=1; $given_array = array("favorites"=>$favorites, "recent"=>$recent); $abc = order_array($given_array); function order_array ($given_array) { sort($given_array); foreach($given_array as $key => $value) { echo $value . ':'; } } ?> This code returns "1:2:" The problem is, this is returning the values of the strings that were defined at the top of the code. Instead of returning their values, i want it to return their names. So in this case, it would return "recent:favorites:" How do i do this? Thanks. Link to comment https://forums.phpfreaks.com/topic/173368-order-code-fix/ Share on other sites More sharing options...
Alex Posted September 7, 2009 Share Posted September 7, 2009 You want to echo the keys of the array? Or the names of the variables? In this case they would be the same.. echo $key . ':'; Link to comment https://forums.phpfreaks.com/topic/173368-order-code-fix/#findComment-913924 Share on other sites More sharing options...
k0z Posted September 7, 2009 Author Share Posted September 7, 2009 You want to echo the keys of the array? Or the names of the variables? In this case they would be the same.. echo $key . ':'; I tried doing that, however this just returns "0:1:" . I guess sort() removes the keys i defined, and turns it into numerical values. Link to comment https://forums.phpfreaks.com/topic/173368-order-code-fix/#findComment-913928 Share on other sites More sharing options...
k0z Posted September 7, 2009 Author Share Posted September 7, 2009 Nevermind. all i need to do is use asort. Link to comment https://forums.phpfreaks.com/topic/173368-order-code-fix/#findComment-913929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.