3v4l.org

run code in 300+ 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"; function sort_most_needles(&$array, $str) { $needles = explode(" ", $str); usort($array, function ($a, $b) use ($needles) { return array_uintersect($needles, explode(" ", $b['title']), 'strcasecmp') <=> array_uintersect($needles, explode(" ", $a['title']), 'strcasecmp'); }); } sort_most_needles($arr, $str); var_export($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fKAsK
function name:  (null)
number of ops:  10
compiled vars:  !0 = $arr, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, 'Hello+world+January+jude'
   19     2        INIT_FCALL                                               'sort_most_needles'
          3        SEND_REF                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0          
   21     6        INIT_FCALL                                               'var_export'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function sort_most_needles:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fKAsK
function name:  sort_most_needles
number of ops:  14
compiled vars:  !0 = $array, !1 = $str, !2 = $needles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
   12     7        INIT_FCALL                                               'usort'
          8        SEND_REF                                                 !0
          9        DECLARE_LAMBDA_FUNCTION                          ~5      [0]
         10        BIND_LEXICAL                                             ~5, !2
   16    11        SEND_VAL                                                 ~5
   12    12        DO_ICALL                                                 
   17    13      > 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/fKAsK
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $a, !1 = $b, !2 = $needles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   13     3        INIT_FCALL                                               'array_uintersect'
          4        SEND_VAR                                                 !2
          5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '+'
          7        FETCH_DIM_R                                      ~3      !1, 'title'
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        SEND_VAL                                                 'strcasecmp'
         12        DO_ICALL                                         $5      
   15    13        INIT_FCALL                                               'array_uintersect'
         14        SEND_VAR                                                 !2
         15        INIT_FCALL                                               'explode'
         16        SEND_VAL                                                 '+'
         17        FETCH_DIM_R                                      ~6      !0, 'title'
         18        SEND_VAL                                                 ~6
         19        DO_ICALL                                         $7      
         20        SEND_VAR                                                 $7
         21        SEND_VAL                                                 'strcasecmp'
         22        DO_ICALL                                         $8      
         23        SPACESHIP                                        ~9      $5, $8
         24      > RETURN                                                   ~9
   16    25*     > RETURN                                                   null

End of Dynamic Function 0

End of function sort_most_needles

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.94 ms | 1012 KiB | 18 Q