Php strncasecmp
From w3cyberlearnings
Contents |
PHP function strnatcmp
This function uses a 'natural order' algorithm for string comparision. This comparision is case-sensitive.
Syntax strnatcmp
- string1: string input.
- string2: string input.
strnatcmp(string1,string2)
Return
- 0: when two string equal.
- >0: string1 is greater than string2.
- <0: string2 is greater than string1.
Example 1
<?php echo strnatcmp ("apple" , "Apple"); ?>
Output
1
Example 2
<?php echo strnatcmp ("apple" , "apple1"); ?>
Output
-1
Example 3
<?php $aa1 = $aa2 = array('app1', 'app0', 'App0', 'app3', 'app12', 'app02', 'app122', 'app2'); echo 'Standard Shorting Order<br/>'; usort($aa1, "strcmp"); print_r($aa1); echo 'Natural Algorithm Order<br/>'; usort($aa2, "strnatcmp"); print_r($aa2); ?>
Output
Standard Shorting Order Array ( [0] => App0 [1] => app0 [2] => app02 [3] => app1 [4] => app12 [5] => app122 [6] => app2 [7] => app3 ) Natural Algorithm Order Array ( [0] => App0 [1] => app0 [2] => app02 [3] => app1 [4] => app2 [5] => app3 [6] => app12 [7] => app122 )