3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!defined('PHP_EOL')) { define('PHP_EOL', "\n"); } function printPerson($person) { echo sprintf( "Name: %s | Age: %s | Color: %s" . PHP_EOL, $person["name"], $person["age"], $person["colour"] ); } $people = array( array("name"=>"Bob","age"=>8,"colour"=>"red"), array("name"=>"Greg","age"=>12,"colour"=>"blue"), array("name"=>"Andy","age"=>5,"colour"=>"purple") ); $arrSortArray = array(); foreach($people as $person) { foreach($person as $key=>$value){ if(!isset($arrSortArray[$key])){ $arrSortArray[$key] = array(); } $arrSortArray[$key][] = $person; } } $orderby = "age"; //change this to whatever key you want from the array echo 'BEFORE SORT' . PHP_EOL; foreach ($arrSortArray[$orderby] as $person) { printPerson($person); } array_multisort($arrSortArray[$orderby], SORT_ASC,$people); echo '------------------------' . PHP_EOL; echo 'AFTER SORT' . PHP_EOL; foreach ($arrSortArray[$orderby] as $person) { printPerson($person); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 1, Position 2 = 5
Branch analysis from position: 1
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 17
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 21
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 49
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
Branch analysis from position: 33
Branch analysis from position: 23
Branch analysis from position: 5
filename:       /in/okEA5
function name:  (null)
number of ops:  51
compiled vars:  !0 = $people, !1 = $arrSortArray, !2 = $person, !3 = $value, !4 = $key, !5 = $orderby
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E > > JMPZ                                                     <false>, ->5
    3     1    >   INIT_FCALL                                               'define'
          2        SEND_VAL                                                 'PHP_EOL'
          3        SEND_VAL                                                 '%0A'
          4        DO_ICALL                                                 
   15     5    >   ASSIGN                                                   !0, <array>
   21     6        ASSIGN                                                   !1, <array>
   23     7      > FE_RESET_R                                       $9      !0, ->23
          8    > > FE_FETCH_R                                               $9, !2, ->23
   24     9    > > FE_RESET_R                                       $10     !2, ->21
         10    > > FE_FETCH_R                                       ~11     $10, !3, ->21
         11    >   ASSIGN                                                   !4, ~11
   25    12        ISSET_ISEMPTY_DIM_OBJ                         0  ~13     !1, !4
         13        BOOL_NOT                                         ~14     ~13
         14      > JMPZ                                                     ~14, ->17
   26    15    >   ASSIGN_DIM                                               !1, !4
         16        OP_DATA                                                  <array>
   28    17    >   FETCH_DIM_W                                      $16     !1, !4
         18        ASSIGN_DIM                                               $16
         19        OP_DATA                                                  !2
   24    20      > JMP                                                      ->10
         21    >   FE_FREE                                                  $10
   23    22      > JMP                                                      ->8
         23    >   FE_FREE                                                  $9
   32    24        ASSIGN                                                   !5, 'age'
   34    25        ECHO                                                     'BEFORE+SORT%0A'
   35    26        FETCH_DIM_R                                      ~19     !1, !5
         27      > FE_RESET_R                                       $20     ~19, ->33
         28    > > FE_FETCH_R                                               $20, !2, ->33
   36    29    >   INIT_FCALL                                               'printperson'
         30        SEND_VAR                                                 !2
         31        DO_FCALL                                      0          
   35    32      > JMP                                                      ->28
         33    >   FE_FREE                                                  $20
   40    34        INIT_FCALL                                               'array_multisort'
         35        FETCH_DIM_W                                      $22     !1, !5
         36        SEND_REF                                                 $22
         37        SEND_VAL                                                 4
         38        SEND_REF                                                 !0
         39        DO_ICALL                                                 
   41    40        ECHO                                                     '------------------------%0A'
   42    41        ECHO                                                     'AFTER+SORT%0A'
   43    42        FETCH_DIM_R                                      ~24     !1, !5
         43      > FE_RESET_R                                       $25     ~24, ->49
         44    > > FE_FETCH_R                                               $25, !2, ->49
   44    45    >   INIT_FCALL                                               'printperson'
         46        SEND_VAR                                                 !2
         47        DO_FCALL                                      0          
   43    48      > JMP                                                      ->44
         49    >   FE_FREE                                                  $25
   45    50      > RETURN                                                   1

Function printperson:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/okEA5
function name:  printPerson
number of ops:  12
compiled vars:  !0 = $person
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        INIT_FCALL                                               'sprintf'
    8     2        SEND_VAL                                                 'Name%3A+%25s+%7C+Age%3A+%25s+%7C+Color%3A+%25s%0A'
    9     3        FETCH_DIM_R                                      ~1      !0, 'name'
          4        SEND_VAL                                                 ~1
   10     5        FETCH_DIM_R                                      ~2      !0, 'age'
          6        SEND_VAL                                                 ~2
   11     7        FETCH_DIM_R                                      ~3      !0, 'colour'
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10        ECHO                                                     $4
   13    11      > RETURN                                                   null

End of function printperson

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.97 ms | 1403 KiB | 21 Q