3v4l.org

run code in 300+ PHP versions simultaneously
<?php $customers='[ { "id": 1, "name": "sara", "phone": 1100, "mobile": 1111 }, { "id": 2, "name": "ben", "phone": 2200, "mobile": 2222 } ]'; $data = json_decode($customers, true); function findCustomerInArr($array,$customerName){ $customerFound = false; foreach($array as $a){ if(strtolower($a['name']) == strtolower($customerName)){ $customerFound = true; echo $customerName."'s phone is ".$a['phone'].PHP_EOL; echo $customerName."'s mobile is ".$a['mobile'].PHP_EOL; break; } } if(false == $customerFound){ echo "No customer found with this name".PHP_EOL; } } findCustomerInArr($data,'sara'); findCustomerInArr($data,'aliveToDie');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fIJXu
function name:  (null)
number of ops:  15
compiled vars:  !0 = $customers, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A+%7B%0A++%22id%22%3A+1%2C%0A++%22name%22%3A+%22sara%22%2C%0A++%22phone%22%3A+1100%2C%0A++%22mobile%22%3A+1111%0A+%7D%2C%0A+%7B%0A++%22id%22%3A+2%2C%0A++%22name%22%3A+%22ben%22%2C%0A++%22phone%22%3A+2200%2C%0A++%22mobile%22%3A+2222%0A+%7D%0A%5D'
   17     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   34     6        INIT_FCALL                                               'findcustomerinarr'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 'sara'
          9        DO_FCALL                                      0          
   35    10        INIT_FCALL                                               'findcustomerinarr'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 'aliveToDie'
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

Function findcustomerinarr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 27
Branch analysis from position: 27
filename:       /in/fIJXu
function name:  findCustomerInArr
number of ops:  32
compiled vars:  !0 = $array, !1 = $customerName, !2 = $customerFound, !3 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        ASSIGN                                                   !2, <false>
   21     3      > FE_RESET_R                                       $5      !0, ->27
          4    > > FE_FETCH_R                                               $5, !3, ->27
   22     5    >   INIT_FCALL                                               'strtolower'
          6        FETCH_DIM_R                                      ~6      !3, 'name'
          7        SEND_VAL                                                 ~6
          8        DO_ICALL                                         $7      
          9        INIT_FCALL                                               'strtolower'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $8      
         12        IS_EQUAL                                                 $7, $8
         13      > JMPZ                                                     ~9, ->26
   23    14    >   ASSIGN                                                   !2, <true>
   24    15        CONCAT                                           ~11     !1, '%27s+phone+is+'
         16        FETCH_DIM_R                                      ~12     !3, 'phone'
         17        CONCAT                                           ~13     ~11, ~12
         18        CONCAT                                           ~14     ~13, '%0A'
         19        ECHO                                                     ~14
   25    20        CONCAT                                           ~15     !1, '%27s+mobile+is+'
         21        FETCH_DIM_R                                      ~16     !3, 'mobile'
         22        CONCAT                                           ~17     ~15, ~16
         23        CONCAT                                           ~18     ~17, '%0A'
         24        ECHO                                                     ~18
   26    25      > JMP                                                      ->27
   21    26    > > JMP                                                      ->4
         27    >   FE_FREE                                                  $5
   29    28        BOOL_NOT                                         ~19     !2
         29      > JMPZ                                                     ~19, ->31
   30    30    >   ECHO                                                     'No+customer+found+with+this+name%0A'
   32    31    > > RETURN                                                   null

End of function findcustomerinarr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.19 ms | 1018 KiB | 17 Q