3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [2, 3, 4, 6]; $array2 = [ ["id_sabor" => 1, "chocolate" => "N"], ["id_sabor" => 2, "chocolate" => "N"], ["id_sabor" => 3, "chocolate" => "S"], ["id_sabor" => 4, "chocolate" => "N"], ["id_sabor" => 5, "chocolate" => "S"], ["id_sabor" => 6, "chocolate" => "N"] ]; $array2 = array_reduce($array2, function($carry, $item) use ($array1){ if (in_array($item["id_sabor"], $array1)) { if ($item["chocolate"] === "S") { $item["costo_extra"] = 25; } $carry[] = $item; } return $carry; }); print_r($array2);
Output for git.master_jit, git.master, rfc.property-hooks
Array ( [0] => Array ( [id_sabor] => 2 [chocolate] => N ) [1] => Array ( [id_sabor] => 3 [chocolate] => S [costo_extra] => 25 ) [2] => Array ( [id_sabor] => 4 [chocolate] => N ) [3] => Array ( [id_sabor] => 6 [chocolate] => N ) )

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:
107.34 ms | 406 KiB | 5 Q