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"; function sort_most_needles(&$array, $str) { $needles = explode(" ", $str); usort($array, fn($a, $b) => 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/uJuni
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'
   20     2        INIT_FCALL                                                   'sort_most_needles'
          3        SEND_REF                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0          
   22     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/uJuni
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
   13     9        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
         10        BIND_LEXICAL                                                 ~5, !2
   17    11        SEND_VAL                                                     ~5
   12    12        DO_ICALL                                                     
   18    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/uJuni
function name:  {closure:sort_most_needles():13}
number of ops:  26
compiled vars:  !0 = $a, !1 = $b, !2 = $needles
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   14     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      
   16    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
   17    25*     > RETURN                                                       null

End of Dynamic Function 0

End of function sort_most_needles

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.69 ms | 2250 KiB | 18 Q