3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fill_packages( $packages ) { $overrun = 42; // Items in cart $cost = 0; $filled = array(); $quantities = array(); foreach( $packages as $the_package ){ $delivers = floor( $overrun / $the_package['contain'] ); if( ! $delivers ) { continue; } $filled[$the_package['name']] = $delivers; $overrun = $overrun - ( $delivers * $the_package['contain'] ); $cost = $cost + ( $delivers * $the_package['cost'] ); } if( $overrun ) { return 'Error, Overrun of ' . $overrun . '!'; } return array( 'packages' => $filled, 'cost' => $cost, ); } /* Test it! */ print_r( fill_packages( array( array( 'name' => '18er', 'contain' => 18, 'cost' => 5 ), array( 'name' => '12er', 'contain' => 12, 'cost' => 5 ), array( 'name' => '6er', 'contain' => 6, 'cost' => 8 ), ) ) );
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [packages] => Array ( [18er] => 2 [6er] => 1 ) [cost] => 18 )

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:
112.19 ms | 405 KiB | 5 Q