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) { return (array_search($foto['tamano'], $weight) < array_search($item['tamano'], $weight)) ? $foto : $item; }, $fotos[0]); 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/r2kO8 on line 19 Warning: {closure}(): Argument #1 ($foto) must be passed by reference, value given in /in/r2kO8 on line 19 Warning: {closure}(): Argument #1 ($foto) must be passed by reference, value given in /in/r2kO8 on line 19 array(2) { ["idAdjunto"]=> int(2) ["tamano"]=> string(7) "Galeria" }

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:
39.22 ms | 402 KiB | 8 Q