3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weight = array('Galeria' => 4, 'Rss' => 3, 'Grande' => 2, 'Mediana' => 1); var_dump($weight); die; //$weight = array(1, 3, 5); $options = array('Chico', 'Grande', 'Rss', 'Galeria', 'Grande', 'Mediana'); // de las opciones disponibles obtener la de mayor peso $options = array_filter($options, function($item) use ($weight) {return in_array($item, $weight);}); $option = array_reduce($options, function(&$option, $item) use ($weight) { echo $item . PHP_EOL; return ($weight[$option] > $weight[$item]) ? $option : $item; //return ($option > $item) ? $option : $item; }); var_dump($option); die; $tamano = 'Rss'; echo $attachmentSizes[$tamano]; die; $fotos = array(array('idAdjunto' => 1, 'tamano' => 'Grande'), array('idAdjunto' => 2, 'tamano'=>'Galeria'), array('idAdjunto' => 3, 'tamano'=>'Mediana')); $foto = array_filter($fotos, function($foto) use ($attachmentSizes) { return in_array($foto['tamano'], $attachmentSizes); }); $foto = array_shift($foto); var_dump($foto);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/3uMuv
function name:  (null)
number of ops:  44
compiled vars:  !0 = $weight, !1 = $options, !2 = $option, !3 = $tamano, !4 = $attachmentSizes, !5 = $fotos, !6 = $foto
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
    5     4      > EXIT                                                     
    7     5*       ASSIGN                                                   !1, <array>
   11     6*       INIT_FCALL                                               'array_filter'
          7*       SEND_VAR                                                 !1
          8*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F3uMuv%3A11%240'
          9*       BIND_LEXICAL                                             ~10, !0
         10*       SEND_VAL                                                 ~10
         11*       DO_ICALL                                         $11     
         12*       ASSIGN                                                   !1, $11
   12    13*       INIT_FCALL                                               'array_reduce'
         14*       SEND_VAR                                                 !1
         15*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F3uMuv%3A12%241'
         16*       BIND_LEXICAL                                             ~13, !0
   17    17*       SEND_VAL                                                 ~13
         18*       DO_ICALL                                         $14     
   12    19*       ASSIGN                                                   !2, $14
   19    20*       INIT_FCALL                                               'var_dump'
         21*       SEND_VAR                                                 !2
         22*       DO_ICALL                                                 
   20    23*       EXIT                                                     
   24    24*       ASSIGN                                                   !3, 'Rss'
   25    25*       FETCH_DIM_R                                      ~18     !4, !3
         26*       ECHO                                                     ~18
   26    27*       EXIT                                                     
   28    28*       ASSIGN                                                   !5, <array>
   30    29*       INIT_FCALL                                               'array_filter'
         30*       SEND_VAR                                                 !5
         31*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F3uMuv%3A30%242'
         32*       BIND_LEXICAL                                             ~20, !4
   32    33*       SEND_VAL                                                 ~20
         34*       DO_ICALL                                         $21     
   30    35*       ASSIGN                                                   !6, $21
   33    36*       INIT_FCALL                                               'array_shift'
         37*       SEND_REF                                                 !6
         38*       DO_ICALL                                         $23     
         39*       ASSIGN                                                   !6, $23
   35    40*       INIT_FCALL                                               'var_dump'
         41*       SEND_VAR                                                 !6
         42*       DO_ICALL                                                 
         43*     > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F3uMuv%3A11%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3uMuv
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item, !1 = $weight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
          7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F3uMuv%3A11%240

Function %00%7Bclosure%7D%2Fin%2F3uMuv%3A12%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3uMuv
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $option, !1 = $item, !2 = $weight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   13     3        CONCAT                                           ~3      !1, '%0A'
          4        ECHO                                                     ~3
   15     5        FETCH_DIM_R                                      ~4      !2, !0
          6        FETCH_DIM_R                                      ~5      !2, !1
          7        IS_SMALLER                                               ~5, ~4
          8      > JMPZ                                                     ~6, ->11
          9    >   QM_ASSIGN                                        ~7      !0
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~7      !1
         12    > > RETURN                                                   ~7
   17    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F3uMuv%3A12%241

Function %00%7Bclosure%7D%2Fin%2F3uMuv%3A30%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3uMuv
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $foto, !1 = $attachmentSizes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   31     2        INIT_FCALL                                               'in_array'
          3        FETCH_DIM_R                                      ~2      !0, 'tamano'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
   32     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F3uMuv%3A30%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.21 ms | 1404 KiB | 23 Q