3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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 = "name"; //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 = 77) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 12
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 44
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 44
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 28
Branch analysis from position: 18
filename:       /in/srODF
function name:  (null)
number of ops:  46
compiled vars:  !0 = $people, !1 = $arrSortArray, !2 = $person, !3 = $value, !4 = $key, !5 = $orderby
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   18     1        ASSIGN                                                   !1, <array>
   20     2      > FE_RESET_R                                       $8      !0, ->18
          3    > > FE_FETCH_R                                               $8, !2, ->18
   21     4    > > FE_RESET_R                                       $9      !2, ->16
          5    > > FE_FETCH_R                                       ~10     $9, !3, ->16
          6    >   ASSIGN                                                   !4, ~10
   22     7        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !1, !4
          8        BOOL_NOT                                         ~13     ~12
          9      > JMPZ                                                     ~13, ->12
   23    10    >   ASSIGN_DIM                                               !1, !4
         11        OP_DATA                                                  <array>
   25    12    >   FETCH_DIM_W                                      $15     !1, !4
         13        ASSIGN_DIM                                               $15
         14        OP_DATA                                                  !2
   21    15      > JMP                                                      ->5
         16    >   FE_FREE                                                  $9
   20    17      > JMP                                                      ->3
         18    >   FE_FREE                                                  $8
   29    19        ASSIGN                                                   !5, 'name'
   31    20        ECHO                                                     'BEFORE+SORT%0A'
   32    21        FETCH_DIM_R                                      ~18     !1, !5
         22      > FE_RESET_R                                       $19     ~18, ->28
         23    > > FE_FETCH_R                                               $19, !2, ->28
   33    24    >   INIT_FCALL                                               'printperson'
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0          
   32    27      > JMP                                                      ->23
         28    >   FE_FREE                                                  $19
   37    29        INIT_FCALL                                               'array_multisort'
         30        FETCH_DIM_W                                      $21     !1, !5
         31        SEND_REF                                                 $21
         32        SEND_VAL                                                 4
         33        SEND_REF                                                 !0
         34        DO_ICALL                                                 
   38    35        ECHO                                                     '------------------------%0A'
   39    36        ECHO                                                     'AFTER+SORT%0A'
   40    37        FETCH_DIM_R                                      ~23     !1, !5
         38      > FE_RESET_R                                       $24     ~23, ->44
         39    > > FE_FETCH_R                                               $24, !2, ->44
   41    40    >   INIT_FCALL                                               'printperson'
         41        SEND_VAR                                                 !2
         42        DO_FCALL                                      0          
   40    43      > JMP                                                      ->39
         44    >   FE_FREE                                                  $24
   42    45      > RETURN                                                   1

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

End of function printperson

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.16 ms | 1394 KiB | 19 Q