3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = array(array("id" => 1,"title" => "Hello world", "body" => "Hi Jude All this is my content"), array("id" => 2,"title" => "Hello world Boy", "body" => "Hi All this is my content Girl"), array("id" => 3,"title" => "hello Kids", "body" => "Hi All this is my content Kid"), array("id" => 4,"title" => "Hello World Jude", "body" => "Hi All this is my content Jude"), array("id" => 5,"title" => "Hello World Jude January", "body" => "Hi All this is my content Jan"), array("id" => 6,"title" => "Hello World January June Lord", "body" => "Hi All this is my content Jan Jude Lord")); $str = "hello world january jude"; $arr2 = sort_most_exists_asc($arr, $str); var_dump($arr2); function sort_most_exists_asc($array, $str) { usort($array, function ($a, $b) use ($str) { $aa = count(array_uintersect(explode(" ", $str), explode(" ", $a['title']), 'strcasecmp')); $bb = count(array_uintersect(explode(" ", $str), explode(" ", $b['title']), 'strcasecmp')); return $bb - $aa; }); return $array; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tlvbh
function name:  (null)
number of ops:  11
compiled vars:  !0 = $arr, !1 = $str, !2 = $arr2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, 'hello+world+january+jude'
   10     2        INIT_FCALL_BY_NAME                                           'sort_most_exists_asc'
          3        SEND_VAR_EX                                                  !0
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                                       !2, $5
   11     7        INIT_FCALL                                                   'var_dump'
          8        SEND_VAR                                                     !2
          9        DO_ICALL                                                     
   21    10      > RETURN                                                       1

Function sort_most_exists_asc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tlvbh
function name:  sort_most_exists_asc
number of ops:  10
compiled vars:  !0 = $array, !1 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   15     2        INIT_FCALL                                                   'usort'
          3        SEND_REF                                                     !0
          4        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          5        BIND_LEXICAL                                                 ~2, !1
   19     6        SEND_VAL                                                     ~2
   15     7        DO_ICALL                                                     
   20     8      > RETURN                                                       !0
   21     9*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tlvbh
function name:  {closure:sort_most_exists_asc():15}
number of ops:  38
compiled vars:  !0 = $a, !1 = $b, !2 = $str, !3 = $aa, !4 = $bb
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   16     3        INIT_FCALL                                                   'array_uintersect'
          4        INIT_FCALL                                                   'explode'
          5        SEND_VAL                                                     '+'
          6        SEND_VAR                                                     !2
          7        DO_ICALL                                             $5      
          8        SEND_VAR                                                     $5
          9        INIT_FCALL                                                   'explode'
         10        SEND_VAL                                                     '+'
         11        FETCH_DIM_R                                          ~6      !0, 'title'
         12        SEND_VAL                                                     ~6
         13        DO_ICALL                                             $7      
         14        SEND_VAR                                                     $7
         15        SEND_VAL                                                     'strcasecmp'
         16        DO_ICALL                                             $8      
         17        COUNT                                                ~9      $8
         18        ASSIGN                                                       !3, ~9
   17    19        INIT_FCALL                                                   'array_uintersect'
         20        INIT_FCALL                                                   'explode'
         21        SEND_VAL                                                     '+'
         22        SEND_VAR                                                     !2
         23        DO_ICALL                                             $11     
         24        SEND_VAR                                                     $11
         25        INIT_FCALL                                                   'explode'
         26        SEND_VAL                                                     '+'
         27        FETCH_DIM_R                                          ~12     !1, 'title'
         28        SEND_VAL                                                     ~12
         29        DO_ICALL                                             $13     
         30        SEND_VAR                                                     $13
         31        SEND_VAL                                                     'strcasecmp'
         32        DO_ICALL                                             $14     
         33        COUNT                                                ~15     $14
         34        ASSIGN                                                       !4, ~15
   18    35        SUB                                                  ~17     !4, !3
         36      > RETURN                                                       ~17
   19    37*     > RETURN                                                       null

End of Dynamic Function 0

End of function sort_most_exists_asc

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
221.13 ms | 2342 KiB | 17 Q