Search code examples
phpsorting

sort( $new, SORT_NATURAL | SORT_FLAG_CASE ) in PHP 5.3


sort( $new, SORT_NATURAL | SORT_FLAG_CASE );

SORT_NATURAL is new in php 5.4 but i have 5.3.10 running on my localhost (ubuntu 12.04) not really intention to upgrade because of that.

What would be the equivalent in php 5.3, i have read that is just like natsort.

is natsort( $new, SORT_FLAG_CASE ); the same ?


Solution

  • The PHP Manual points out that natsort ($array) is the equivalent of sort($array,SORT_NATURAL); it also points that SORT_FLAG_CASE wasn't added until 5.4.0 either.

    You can use natcasesort($array) which is the equivalent of sort($array,SORT_NATURAL | SORT_FLAG_CASE).