fork(1) download
  1. <?php
  2.  
  3. function cmp ($a, $b) {
  4. return strcmp(substr($a, 0, $num), substr($a, 0, $num));
  5. }
  6.  
  7. $terms = ['123a', '123z', '123b',];
  8. $num = 3;$thing=3;
  9. usort($terms, [$num, $thing, "cmp"]);
  10.  
  11. print_r($terms);
Success #stdin #stdout #stderr 0.03s 25768KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 123a
    [1] => 123z
    [2] => 123b
)
stderr
PHP Warning:  usort() expects parameter 2 to be a valid callback, array must have exactly two members in /home/fvM5UX/prog.php on line 9