how to sort array of strings in php? Here strings are the paths. e.g. /root/mandy/a.pdf, b.pdf & c.pdf etc
.
I tried with sort()
function with it's parameters, however it's not working ?
EDIT (based on OP's comments):
My bad ! I haven't posted this question correctly. Apologies...
Actually it's an array of maps [not sure may be array of array] -> array("path => "file_name")
& i need to sort it accordingly the file_name
.
$strings = array('/root/mandy/c.pdf', '/root/mandy/a.pdf', '/root/mandy/b.pdf');
sort($strings);
print_r($strings);
It works for me.
Or even better, use strcmp to compare the strings
uasort($yourArray, function ($a, $b) {
return strcmp($a['path'], $b['path']);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With