3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cityID = '2'; $oldCityFound = false; $newCityFound = false; $arr = [ '1' => ['ID'=>'1', 'NAME'=>'Moscow', 'UF_DEFAULT'=>'1', 'UF_CITY_CORD'=>'55.76, 37.64'], '2' => ['ID'=>'2', 'NAME'=>'Tver', 'UF_DEFAULT'=>'0', 'UF_CITY_CORD'=>'55.76, 37.64'], '3' => ['ID'=>'3', 'NAME'=>'Nahodka', 'UF_DEFAULT'=>'0', 'UF_CITY_CORD'=>'55.76, 37.64'], '4' => ['ID'=>'4', 'NAME'=>'Omsk', 'UF_DEFAULT'=>'0', 'UF_CITY_CORD'=>'55.76, 37.64'], ]; foreach ($arr as &$row) { if ($row['ID'] == $cityID) { if ($row['UF_DEFAULT'] == 1) { break; // nothing to change } $row['UF_DEFAULT'] = 1; $newCityFound = true; } elseif ($row['UF_DEFAULT'] == 1) { $row['UF_DEFAULT'] = 0; $oldCityFound = true; } if ($newCityFound && $oldCityFound) { break; // both jobs done ...efficiently } } unset($row); // best practice var_export($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 5, Position 2 = 28
Branch analysis from position: 5
2 jumps found. (Code = 126) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 25
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
Branch analysis from position: 25
Branch analysis from position: 23
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/qrOpi
function name:  (null)
number of ops:  34
compiled vars:  !0 = $cityID, !1 = $oldCityFound, !2 = $newCityFound, !3 = $arr, !4 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '2'
    3     1        ASSIGN                                                   !1, <false>
    4     2        ASSIGN                                                   !2, <false>
    5     3        ASSIGN                                                   !3, <array>
   11     4      > FE_RESET_RW                                      $9      !3, ->28
          5    > > FE_FETCH_RW                                              $9, !4, ->28
   12     6    >   FETCH_DIM_R                                      ~10     !4, 'ID'
          7        IS_EQUAL                                                 !0, ~10
          8      > JMPZ                                                     ~11, ->17
   13     9    >   FETCH_DIM_R                                      ~12     !4, 'UF_DEFAULT'
         10        IS_EQUAL                                                 ~12, 1
         11      > JMPZ                                                     ~13, ->13
   14    12    > > JMP                                                      ->28
   16    13    >   ASSIGN_DIM                                               !4, 'UF_DEFAULT'
         14        OP_DATA                                                  1
   17    15        ASSIGN                                                   !2, <true>
   12    16      > JMP                                                      ->23
   18    17    >   FETCH_DIM_R                                      ~16     !4, 'UF_DEFAULT'
         18        IS_EQUAL                                                 ~16, 1
         19      > JMPZ                                                     ~17, ->23
   19    20    >   ASSIGN_DIM                                               !4, 'UF_DEFAULT'
         21        OP_DATA                                                  0
   20    22        ASSIGN                                                   !1, <true>
   22    23    > > JMPZ_EX                                          ~20     !2, ->25
         24    >   BOOL                                             ~20     !1
         25    > > JMPZ                                                     ~20, ->27
   23    26    > > JMP                                                      ->28
   11    27    > > JMP                                                      ->5
         28    >   FE_FREE                                                  $9
   26    29        UNSET_CV                                                 !4
   27    30        INIT_FCALL                                               'var_export'
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.36 ms | 1015 KiB | 14 Q