Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts

    Remove keys from an array but keep values in order

    I have an array that I create in wordpress using some custom post types, and because I can't figure out how to actually get it to sort by the dates associated with that post type, I've stored them all into an array, using their timestamp as their key value, and then sorted on the key, no problem.

    The issue is when I go ahead and loop though this newly sorted array, I need to know what the current item in the loop is and what if any the next item is. Because of that, I'm trying to figure out how I can drop all the key values so it defaults back to the basic 0, 1, 2, 3, ...

    Anyone know how I can do this? If I'm overthinking this or there is a better solution? I could make an array of the keys and then loop though them as well and create a second associative array but I feel like its the wrong way to go. Anyone have any suggestions for me?

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Of course, even though I was using the array_keys to come up with a alternate solution, it just didn't click... if array_keys gets the arrays keys... maybe array_values will get the array's values!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •