3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weight = array('Galeria', 'Rss', 'Grande', 'Mediana'); echo array_search('Galeria', $weight); echo array_search('asd', $weight); die; //$weight = array(1, 3, 5); $options = array('Chico', 'Grande', 'Rss', '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 (array_search($option, $weight) < array_search($item, $weight)) ? $option : $item; //return ($option > $item) ? $option : $item; }, 'Galeria'); 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/ftXlF
function name:  (null)
number of ops:  52
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>
    5     1        INIT_FCALL                                               'array_search'
          2        SEND_VAL                                                 'Galeria'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $8      
          5        ECHO                                                     $8
    6     6        INIT_FCALL                                               'array_search'
          7        SEND_VAL                                                 'asd'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10        ECHO                                                     $9
    7    11      > EXIT                                                     
   10    12*       ASSIGN                                                   !1, <array>
   14    13*       INIT_FCALL                                               'array_filter'
         14*       SEND_VAR                                                 !1
         15*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FftXlF%3A14%240'
         16*       BIND_LEXICAL                                             ~11, !0
         17*       SEND_VAL                                                 ~11
         18*       DO_ICALL                                         $12     
         19*       ASSIGN                                                   !1, $12
   15    20*       INIT_FCALL                                               'array_reduce'
         21*       SEND_VAR                                                 !1
         22*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FftXlF%3A15%241'
         23*       BIND_LEXICAL                                             ~14, !0
   20    24*       SEND_VAL                                                 ~14
         25*       SEND_VAL                                                 'Galeria'
         26*       DO_ICALL                                         $15     
   15    27*       ASSIGN                                                   !2, $15
   22    28*       INIT_FCALL                                               'var_dump'
         29*       SEND_VAR                                                 !2
         30*       DO_ICALL                                                 
   23    31*       EXIT                                                     
   27    32*       ASSIGN                                                   !3, 'Rss'
   28    33*       FETCH_DIM_R                                      ~19     !4, !3
         34*       ECHO                                                     ~19
   29    35*       EXIT                                                     
   31    36*       ASSIGN                                                   !5, <array>
   33    37*       INIT_FCALL                                               'array_filter'
         38*       SEND_VAR                                                 !5
         39*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FftXlF%3A33%242'
         40*       BIND_LEXICAL                                             ~21, !4
   35    41*       SEND_VAL                                                 ~21
         42*       DO_ICALL                                         $22     
   33    43*       ASSIGN                                                   !6, $22
   36    44*       INIT_FCALL                                               'array_shift'
         45*       SEND_REF                                                 !6
         46*       DO_ICALL                                         $24     
         47*       ASSIGN                                                   !6, $24
   38    48*       INIT_FCALL                                               'var_dump'
         49*       SEND_VAR                                                 !6
         50*       DO_ICALL                                                 
         51*     > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FftXlF%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ftXlF
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $item, !1 = $weight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     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%2FftXlF%3A14%240

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

End of function %00%7Bclosure%7D%2Fin%2FftXlF%3A15%241

Function %00%7Bclosure%7D%2Fin%2FftXlF%3A33%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ftXlF
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $foto, !1 = $attachmentSizes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   34     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
   35     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FftXlF%3A33%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.86 ms | 1404 KiB | 25 Q