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 ?
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)
.
While they are essentially the same, the important difference to note between natsort($array)
and sort($array, SORT_NATURAL)
is key associations.
natsort()
maintains key associations, meaning that keys and values are kept linked.
However, sort()
does NOT main associations, so values are reassigned keys based on their new order.
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