How to sort an array in PHP while it retrieve using forloop
Here is my actual requirement开发者_运维知识库 (edited)
array('1-One','2-second','10-ten','3-third','11-elevan','4-four')
How can I print the above array as
1-One
2-second
3-third
4-four
10-ten
11-elevan
ie by the sort order of prefix number
sort($array,SORT_NUMERIC);//add extra parameter to change default sorting behave
print_r($array);
DEMO
Use sort before you print your array.
$array = array(1,10,2,12,3);
sort($array);
print_r($array);
精彩评论