adrian Posted April 19, 2013 Share Posted April 19, 2013 Hey guys, Is there any way to emulate PHP's natsort using PW's sort functionality? I have image filenames with numbered suffixes and of course they aren't ordering correctly with a standard sort. Thanks Link to comment Share on other sites More sharing options...
Wanze Posted April 19, 2013 Share Posted April 19, 2013 Without emulating $imgArray = $images->getArray(); natsort($imgArray); // continue with $imgArray or... $images = new WireArray(); $images->import($imgArray); Not tested 2 Link to comment Share on other sites More sharing options...
adrian Posted April 19, 2013 Author Share Posted April 19, 2013 Thanks Wanze, Was hoping there was a PW way. I ended up using the following: $images = $page->$image_field->getArray(); natsort($images); $reversed_images = array_reverse($images); $sortedImages = new WireArray(); $sortedImages->import($reversed_images); $page->$image_field = $sortedImages; I had to reverse the array, I am guessing because of the way import brings them in, so that they are in the correct ascending order. After the final line I make a few more changes to the $page and then save it. Anyway, this seems to work fine. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now