A
A
alekssamos2019-08-29 17:26:05
PHP
alekssamos, 2019-08-29 17:26:05

Sort strings in array by numbers?

There is an array, it seems to be sorted alphabetically, there are file names:
f.pdf-0.jpg, f.pdf-1.jpg, f.pdf-10.jpg, f.pdf-11.jpg, f.pdf -12.jpg, ..., f.pdf-19.jpg, f.pdf-2.jpg, f.pdf-20.jpg, f.pdf-21.jpg ...
i.e. 0, 1, 10 , 11, ..., 2, 20, 21 ...
And I need to sort it by numbers so that it would be normal: 0, 1, 2, 3, ..., 9, 10, 11, ..., 19 , 20, 21...
Tell me how to do it? And then the text is not in order, but mixed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2019-08-29
@alekssamos

https://www.php.net/manual/ru/function.sort.php
https://ideone.com/Ug6Axr

A
Arman, 2019-08-29
@Arik

https://www.php.net/manual/ru/function.natsort.php ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question