3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allOptions = array( array("clID"=> 171), array("clID"=> 191), array("clID"=> 131), array("clID"=> 101), array("clID"=> 201), array("clID"=> 181), array("clID"=> 99), // not in regOptions array("clID"=> 129), // not in regOptions array("clID"=> 139), ) ; $regOptions = array( array("order"=>1,"optID"=> 131), array("order"=>2,"optID"=> 191), array("order"=>3,"optID"=> 181), array("order"=>4,"optID"=> 139), array("order"=>5,"optID"=> 101), array("order"=>6,"optID"=> 201), array("order"=>7,"optID"=> 171) ); // add indexes to the original array for faster lookups $indexedOptions = []; foreach($allOptions as $val) { $indexedOptions[$val['clID']] = $val; } $newArray = []; foreach ($regOptions as $order) { $id = $order['optID']; if (isset($indexedOptions[$id])) { $newArray[] = $indexedOptions[$id]; unset($indexedOptions[$id]); } } // at this point, $newArray has all of the found values in order, // and $indexedOptions has any remaining items. // var_dump($newArray); // var_dump($indexedOptions); // put them together for the final array $final = array_merge($newArray, $indexedOptions); var_dump($final);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 9
filename:       /in/jd5Rq
function name:  (null)
number of ops:  32
compiled vars:  !0 = $allOptions, !1 = $regOptions, !2 = $indexedOptions, !3 = $val, !4 = $newArray, !5 = $order, !6 = $id, !7 = $final
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   26     2        ASSIGN                                                   !2, <array>
   27     3      > FE_RESET_R                                       $11     !0, ->9
          4    > > FE_FETCH_R                                               $11, !3, ->9
   28     5    >   FETCH_DIM_R                                      ~12     !3, 'clID'
          6        ASSIGN_DIM                                               !2, ~12
          7        OP_DATA                                                  !3
   27     8      > JMP                                                      ->4
          9    >   FE_FREE                                                  $11
   31    10        ASSIGN                                                   !4, <array>
   32    11      > FE_RESET_R                                       $15     !1, ->22
         12    > > FE_FETCH_R                                               $15, !5, ->22
   33    13    >   FETCH_DIM_R                                      ~16     !5, 'optID'
         14        ASSIGN                                                   !6, ~16
   35    15        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !6
         16      > JMPZ                                                     ~18, ->21
   36    17    >   FETCH_DIM_R                                      ~20     !2, !6
         18        ASSIGN_DIM                                               !4
         19        OP_DATA                                                  ~20
   37    20        UNSET_DIM                                                !2, !6
   32    21    > > JMP                                                      ->12
         22    >   FE_FREE                                                  $15
   47    23        INIT_FCALL                                               'array_merge'
         24        SEND_VAR                                                 !4
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                         $21     
         27        ASSIGN                                                   !7, $21
   49    28        INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !7
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.77 ms | 1000 KiB | 15 Q