3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array ( array ( 'result_title' => 'Agathoklis Georgiou', 'result_subtext' => 'Active Employee' ), array ( 'result_title' => 'Frixos Georgiou', 'result_subtext' => 'Active Employee' ), array ( 'result_title' => 'George Ellinas', 'result_subtext' => 'Active Employee' ), array ( 'result_title' => 'Fred Ellinas', 'result_subtext' => 'Active Employee' ), array ( 'result_title' => 'Georgi Georgiev', 'result_subtext' => 'Active Employee' ), array ( 'result_title' => 'Charalambos Georgiou', 'result_subtext' => 'Former Employee' ), array ( 'result_title' => 'Georgia Kantouna', 'result_subtext' => 'Former Employee' ) ); $term = 'geo'; usort($data, function ($a, $b) use ($term) { // find the term in first entry $t1 = preg_match("/^.*?\b($term\w+).*\$/i", $a['result_title'], $matches) ? $matches[1] : ''; // find the term in second entry $t2 = preg_match("/^.*?\b($term\w+).*\$/i", $b['result_title'], $matches) ? $matches[1] : ''; // check if the terms were found if ($t1 == '' && $t2 != '') return 1; if ($t1 != '' && $t2 == '') return -1; // found in both - if not the same, just sort on the keyword if ($t1 != $t2) return strcmp($t1, $t2); // found the same keyword, sort on the whole title return strcmp($a['result_title'], $b['result_title']); }); print_r($data);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f6TCW
function name:  (null)
number of ops:  12
compiled vars:  !0 = $data, !1 = $term
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   45     1        ASSIGN                                                   !1, 'geo'
   46     2        INIT_FCALL                                               'usort'
          3        SEND_REF                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ff6TCW%3A46%240'
          5        BIND_LEXICAL                                             ~4, !1
   58     6        SEND_VAL                                                 ~4
          7        DO_ICALL                                                 
   59     8        INIT_FCALL                                               'print_r'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Ff6TCW%3A46%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 46) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 45
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 52
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 37
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
Branch analysis from position: 31
filename:       /in/f6TCW
function name:  {closure}
number of ops:  60
compiled vars:  !0 = $a, !1 = $b, !2 = $term, !3 = $t1, !4 = $matches, !5 = $t2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   48     3        INIT_FCALL                                               'preg_match'
          4        ROPE_INIT                                     3  ~7      '%2F%5E.%2A%3F%5Cb%28'
          5        ROPE_ADD                                      1  ~7      ~7, !2
          6        ROPE_END                                      2  ~6      ~7, '%5Cw%2B%29.%2A%24%2Fi'
          7        SEND_VAL                                                 ~6
          8        FETCH_DIM_R                                      ~9      !0, 'result_title'
          9        SEND_VAL                                                 ~9
         10        SEND_REF                                                 !4
         11        DO_ICALL                                         $10     
         12      > JMPZ                                                     $10, ->16
         13    >   FETCH_DIM_R                                      ~11     !4, 1
         14        QM_ASSIGN                                        ~12     ~11
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~12     ''
         17    >   ASSIGN                                                   !3, ~12
   50    18        INIT_FCALL                                               'preg_match'
         19        ROPE_INIT                                     3  ~15     '%2F%5E.%2A%3F%5Cb%28'
         20        ROPE_ADD                                      1  ~15     ~15, !2
         21        ROPE_END                                      2  ~14     ~15, '%5Cw%2B%29.%2A%24%2Fi'
         22        SEND_VAL                                                 ~14
         23        FETCH_DIM_R                                      ~17     !1, 'result_title'
         24        SEND_VAL                                                 ~17
         25        SEND_REF                                                 !4
         26        DO_ICALL                                         $18     
         27      > JMPZ                                                     $18, ->31
         28    >   FETCH_DIM_R                                      ~19     !4, 1
         29        QM_ASSIGN                                        ~20     ~19
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~20     ''
         32    >   ASSIGN                                                   !5, ~20
   52    33        IS_EQUAL                                         ~22     !3, ''
         34      > JMPZ_EX                                          ~22     ~22, ->37
         35    >   IS_NOT_EQUAL                                     ~23     !5, ''
         36        BOOL                                             ~22     ~23
         37    > > JMPZ                                                     ~22, ->39
         38    > > RETURN                                                   1
   53    39    >   IS_NOT_EQUAL                                     ~24     !3, ''
         40      > JMPZ_EX                                          ~24     ~24, ->43
         41    >   IS_EQUAL                                         ~25     !5, ''
         42        BOOL                                             ~24     ~25
         43    > > JMPZ                                                     ~24, ->45
         44    > > RETURN                                                   -1
   55    45    >   IS_NOT_EQUAL                                             !3, !5
         46      > JMPZ                                                     ~26, ->52
         47    >   INIT_FCALL                                               'strcmp'
         48        SEND_VAR                                                 !3
         49        SEND_VAR                                                 !5
         50        DO_ICALL                                         $27     
         51      > RETURN                                                   $27
   57    52    >   INIT_FCALL                                               'strcmp'
         53        FETCH_DIM_R                                      ~28     !0, 'result_title'
         54        SEND_VAL                                                 ~28
         55        FETCH_DIM_R                                      ~29     !1, 'result_title'
         56        SEND_VAL                                                 ~29
         57        DO_ICALL                                         $30     
         58      > RETURN                                                   $30
   58    59*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ff6TCW%3A46%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
133.94 ms | 1409 KiB | 21 Q