3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weight = array('Galeria', 'Rss', 'Grande', 'Mediana'); //$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) { // return (array_search($option, $weight) < array_search($item, $weight)) ? $option : $item; // }, 'Mediana'); $fotos = array(array('idAdjunto' => 1, 'tamano' => 'Grande'), array('idAdjunto' => 2, 'tamano'=> 'Galeria'), array('idAdjunto' => 3, 'tamano'=> 'Mediana')); $fotos = array_filter($fotos, function($foto) use ($weight) {return in_array($foto['tamano'], $weight);}); $foto = array_reduce($fotos, function(&$foto, $item) use ($weight) { var_dump($foto); die; return (array_search($foto['tamano'], $weight) < array_search($item['tamano'], $weight)) ? $foto : $item; }, 'Mediana'); var_dump($foto);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EfWla
function name:  (null)
number of ops:  22
compiled vars:  !0 = $weight, !1 = $options, !2 = $fotos, !3 = $foto
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
   13     2        ASSIGN                                                   !2, <array>
   17     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !2
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEfWla%3A17%240'
          6        BIND_LEXICAL                                             ~7, !0
          7        SEND_VAL                                                 ~7
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !2, $8
   19    10        INIT_FCALL                                               'array_reduce'
         11        SEND_VAR                                                 !2
         12        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEfWla%3A19%241'
         13        BIND_LEXICAL                                             ~10, !0
   23    14        SEND_VAL                                                 ~10
         15        SEND_VAL                                                 'Mediana'
         16        DO_ICALL                                         $11     
   19    17        ASSIGN                                                   !3, $11
   25    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FEfWla%3A17%240

Function %00%7Bclosure%7D%2Fin%2FEfWla%3A19%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/EfWla
function name:  {closure}
number of ops:  24
compiled vars:  !0 = $foto, !1 = $item, !2 = $weight
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   20     3        INIT_FCALL                                               'var_dump'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   21     6      > EXIT                                                     
   22     7*       INIT_FCALL                                               'array_search'
          8*       FETCH_DIM_R                                      ~4      !0, 'tamano'
          9*       SEND_VAL                                                 ~4
         10*       SEND_VAR                                                 !2
         11*       DO_ICALL                                         $5      
         12*       INIT_FCALL                                               'array_search'
         13*       FETCH_DIM_R                                      ~6      !1, 'tamano'
         14*       SEND_VAL                                                 ~6
         15*       SEND_VAR                                                 !2
         16*       DO_ICALL                                         $7      
         17*       IS_SMALLER                                               $5, $7
         18*       JMPZ                                                     ~8, ->21
         19*       QM_ASSIGN                                        ~9      !0
         20*       JMP                                                      ->22
         21*       QM_ASSIGN                                        ~9      !1
         22*       RETURN                                                   ~9
   23    23*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FEfWla%3A19%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.55 ms | 1400 KiB | 23 Q