3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 'code 10 and amount 1000', 'code 10 and amount 200', 'code 10 and amount 300', 'code 20 and amount 2000' ); $output = array(); foreach ($array as $value) { // Extract the values from the string preg_match('/^code\s(.*)\s\sand amount\s(.*)$/', $value, $match); // If no code exists, we have a problem so skip the line if (! isset($match[1])) { continue; } // Make this a bit more readable for future devs $code = (int) $match[1]; $amount = (int) isset($match[2]) ? $match[2] : 0; // If the code exists in the output array, add the value to it if (isset($output[$code])) { $output[$code] += $amount; } else { // Else make the new code have the value $output[$code] = $amount; } } print_r($output); exit;
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [10] => 1500 [20] => 2000 )

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:
43.07 ms | 401 KiB | 8 Q