3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array ( 'header' => array ( 1 => array ( 0 => array ( 'col_pos' => 1, 'sortable' => 1, 'content' => 'Compare', 'ct_help' => 'Comparehelptext..' ), 1 => array ( 'col_pos' => 2, 'sortable' => 1, 'content' => 'Product', 'ct_help' => 'Producthelptext..' ), 2 => array ( 'col_pos' => 3, 'sortable' => 1, 'content' => 'TypeofCover', 'ct_help' => 'Typeofcoverhelptext..' ), 3 => array ( 'col_pos' => 4, 'sortable' => 1, 'content' => 'RoadsideAssistance', 'ct_help' => 'Roadsideassistancehelptext...' ), 4 => array ( 'col_pos' => 5, 'sortable' => 1, 'content' => 'NationwhideRecovery', 'ct_help' => 'NationwideRecoverhelptext...' ), 5 => array ( 'col_pos' => 9, 'sortable' => 1, 'content' => 'Price', 'ct_help' => 'Pricehelptext...' ), 6 => array ( 'col_pos' => 10, 'sortable' => 1, 'ct_help' => '' ) ) ), 'row' => array ( 2 => array ( 0 => array ( 'col_pos' => 1, 'sortable' => 0, 'content' => 'Logo', 'ct_help' => '' ), 1 => array ( 'col_pos' => 2, 'sortable' => 0, 'content' => 'Productcover2', 'sort_value' => 2, 'ct_help' => '' ), 2 => array ( 'col_pos' => 3, 'sortable' => 0, 'content' => 'Vehicle&Personal2', 'sort_value' => 2, 'ct_help' => '' ), 3 => array ( 'col_pos' => 4, 'sortable' => 0, 'content' => '<b>Yes</b>', 'sort_value' => 1, 'ct_help' => '' ), 4 => array ( 'col_pos' => 5, 'sortable' => 0, 'content' => 'No', 'sort_value' => 0, 'ct_help' => '' ), 5 => array ( 'col_pos' => 9, 'sortable' => 0, 'content' => 'from75GBP', 'sort_value' => 75, 'ct_help' => '' ), 6 => array ( 'col_pos' => 10, 'sortable' => 0, 'content' => '<ahref=\\"#2\\">Visitsite></a>', 'ct_help' => '' ), ), 3 => array ( 0 => array ( 'col_pos' => 1, 'sortable' => 0, 'content' => 'Logo', 'ct_help' => '' ), 1 => array ( 'col_pos' => 2, 'sortable' => 0, 'content' => 'Productcover3', 'sort_value' => 3, 'ct_help' => '' ), 2 => array ( 'col_pos' => 3, 'sortable' => 0, 'content' => 'Vehicle&Personal3', 'sort_value' => 3, 'ct_help' => '' ), 3 => array ( 'col_pos' => 4, 'sortable' => 0, 'content' => 'No', 'sort_value' => 0, 'ct_help' => '' ), 4 => array ( 'col_pos' => 5, 'sortable' => 0, 'content' => '<b>Yes</b>', 'sort_value' => 1, 'ct_help' => '' ), 5 => array ( 'col_pos' => 9, 'sortable' => 0, 'content' => 'from73GBP', 'sort_value' => 73, 'ct_help' => '' ), 6 => array ( 'col_pos' => 10, 'sortable' => 0, 'content' => '<ahref=\\"#3\\">Visitsite></a>', 'ct_help' => '' ), ), 4 => array ( 0 => array ( 'col_pos' => 1, 'sortable' => 0, 'content' => 'Logo', 'ct_help' => '' ), 1 => array ( 'col_pos' => 2, 'sortable' => 0, 'content' => 'Productcover4', 'sort_value' => 4, 'ct_help' => '' ), 2 => array ( 'col_pos' => 3, 'sortable' => 0, 'content' => 'Vehicle&Personal4', 'sort_value' => 4, 'ct_help' => '' ), 3 => array ( 'col_pos' => 4, 'sortable' => 0, 'content' => '<b>Yes</b>', 'sort_value' => 1, 'ct_help' => '' ), 4 => array ( 'col_pos' => 5, 'sortable' => 0, 'content' => '<b>Yes</b>', 'sort_value' => 1, 'ct_help' => '' ), 5 => array ( 'col_pos' => 9, 'sortable' => 0, 'content' => 'from84GBP', 'sort_value' => 84, 'ct_help' => '' ), 6 => array ( 'col_pos' => 10, 'sortable' => 0, 'content' => '<ahref=\\"#4\\">Visitsite></a>', 'ct_help' => '' ), ), 5 => array ( 0 => array ( 'col_pos' => 1, 'sortable' => 0, 'content' => 'Logo', 'ct_help' => '' ), 1 => array ( 'col_pos' => 2, 'sortable' => 0, 'content' => 'Productcover5', 'sort_value' => 5, 'ct_help' => '' ), 2 => array ( 'col_pos' => 3, 'sortable' => 0, 'content' => 'Vehicle&Personal5', 'sort_value' => 5, 'ct_help' => '' ), 3 => array ( 'col_pos' => 4, 'sortable' => 0, 'content' => 'No', 'sort_value' => 0, 'ct_help' => '' ), 4 => array ( 'col_pos' => 5, 'sortable' => 0, 'content' => '<b>Yes</b>', 'sort_value' => 1, 'ct_help' => '' ), 5 => array ( 'col_pos' => 9, 'sortable' => 0, 'content' => 'from96GBP', 'sort_value' => 96, 'ct_help' => '' ), 6 => array ( 'col_pos' => 10, 'sortable' => 0, 'content' => '<ahref=\\"#5\\">Visitsite></a>', 'ct_help' => '' ) ) ) ) ; function sort_list($list, $field, $ascending = true) { $headers = array_values($list['header'])[0]; if (($key = array_search($field, array_column($headers, 'content'))) === false || $headers[$key]['sortable'] == 0) { // can't find field or field is not sortable, do nothing return $list; } usort($list['row'], function ($a, $b) use ($key, $ascending) { return $ascending ? $a[$key]['sort_value'] <=> $b[$key]['sort_value'] : $b[$key]['sort_value'] <=> $a[$key]['sort_value']; }); return $list; } print_r(sort_list($data, 'Price'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4kG5p
function name:  (null)
number of ops:  9
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
  304     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'sort_list'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'Price'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function sort_list:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/4kG5p
function name:  sort_list
number of ops:  36
compiled vars:  !0 = $list, !1 = $field, !2 = $ascending, !3 = $headers, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  292     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <true>
  293     3        INIT_FCALL                                               'array_values'
          4        FETCH_DIM_R                                      ~5      !0, 'header'
          5        SEND_VAL                                                 ~5
          6        DO_ICALL                                         $6      
          7        FETCH_DIM_R                                      ~7      $6, 0
          8        ASSIGN                                                   !3, ~7
  294     9        INIT_FCALL                                               'array_search'
         10        SEND_VAR                                                 !1
         11        INIT_FCALL                                               'array_column'
         12        SEND_VAR                                                 !3
         13        SEND_VAL                                                 'content'
         14        DO_ICALL                                         $9      
         15        SEND_VAR                                                 $9
         16        DO_ICALL                                         $10     
         17        ASSIGN                                           ~11     !4, $10
         18        TYPE_CHECK                                    4  ~12     ~11
         19      > JMPNZ_EX                                         ~12     ~12, ->24
         20    >   FETCH_DIM_R                                      ~13     !3, !4
         21        FETCH_DIM_R                                      ~14     ~13, 'sortable'
         22        IS_EQUAL                                         ~15     ~14, 0
         23        BOOL                                             ~12     ~15
         24    > > JMPZ                                                     ~12, ->26
  296    25    > > RETURN                                                   !0
  298    26    >   INIT_FCALL                                               'usort'
         27        FETCH_DIM_W                                      $16     !0, 'row'
         28        SEND_REF                                                 $16
         29        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4kG5p%3A298%240'
         30        BIND_LEXICAL                                             ~17, !4
         31        BIND_LEXICAL                                             ~17, !2
  300    32        SEND_VAL                                                 ~17
         33        DO_ICALL                                                 
  301    34      > RETURN                                                   !0
  302    35*     > RETURN                                                   null

End of function sort_list

Function %00%7Bclosure%7D%2Fin%2F4kG5p%3A298%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4kG5p
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $a, !1 = $b, !2 = $key, !3 = $ascending
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  298     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
  299     4      > JMPZ                                                     !3, ->12
          5    >   FETCH_DIM_R                                      ~4      !0, !2
          6        FETCH_DIM_R                                      ~5      ~4, 'sort_value'
          7        FETCH_DIM_R                                      ~6      !1, !2
          8        FETCH_DIM_R                                      ~7      ~6, 'sort_value'
          9        SPACESHIP                                        ~8      ~5, ~7
         10        QM_ASSIGN                                        ~9      ~8
         11      > JMP                                                      ->18
         12    >   FETCH_DIM_R                                      ~10     !1, !2
         13        FETCH_DIM_R                                      ~11     ~10, 'sort_value'
         14        FETCH_DIM_R                                      ~12     !0, !2
         15        FETCH_DIM_R                                      ~13     ~12, 'sort_value'
         16        SPACESHIP                                        ~14     ~11, ~13
         17        QM_ASSIGN                                        ~9      ~14
         18    > > RETURN                                                   ~9
  300    19*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F4kG5p%3A298%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.38 ms | 1403 KiB | 24 Q