Man*_*nde 3 php arrays sorting string
如何在php中对字符串数组进行排序?字符串是路径。例如/root/mandy/a.pdf, b.pdf & c.pdf etc。
我尝试使用sort()带有参数的函数,但是它不起作用?
编辑(基于OP的评论):
我的错 !我没有正确发布此问题。道歉...
实际上,这是一组地图[not sure may be array of array] -> array("path => "file_name"),我需要对其进行相应的排序file_name。
$strings = array('/root/mandy/c.pdf', '/root/mandy/a.pdf', '/root/mandy/b.pdf');
sort($strings);
print_r($strings);
Run Code Online (Sandbox Code Playgroud)
这个对我有用。
甚至更好,使用strcmp比较字符串
uasort($yourArray, function ($a, $b) {
return strcmp($a['path'], $b['path']);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17919 次 |
| 最近记录: |