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);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: {closure}(): Argument #1 ($foto) must be passed by reference, value given in /in/EfWla on line 19 string(7) "Mediana"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
55.24 ms | 401 KiB | 8 Q