3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ["year"=>"2016","numb"=>1], ["year"=>"2016","numb"=>3], ["year"=>"2017","numb"=>3], ["year"=>"2016","numb"=>1], ["year"=>"2018","numb"=>2] ]; $newArray = []; $years = array_column($array, "year"); foreach($years as $year){ $year_filtered = array_filter($array, function($d)use($year){ return intval($d["year"]) <= intval($year);}); $total = array_sum(array_column($year_filtered, "numb")); $newArray[$year] = $total; } print_r($newArray);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [2016] => 5 [2017] => 8 [2018] => 10 )

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