3v4l.org

run code in 300+ PHP versions simultaneously
<?php $file = [ [0, 'a', 1, 2], [0, 'a', 1, 2], [0, 'b', 1, 2], ]; $fieldNames = [ 'id', 'location', 'blankets', 'sleepingbags' ]; $sumBlankets = []; foreach ($file as $i => $line) { $row = array_combine($fieldNames, $line); $k = $row['location']; // important if (!array_key_exists($k, $sumBlankets)) { $sumBlankets[$k] = ['blankets'=>0, 'sleepingbags'=>0]; } $sumBlankets[$k]['blankets'] += $row['blankets']; $sumBlankets[$k]['sleepingbags'] += $row['sleepingbags']; } var_export( $sumBlankets );
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'a' => array ( 'blankets' => 2, 'sleepingbags' => 4, ), 'b' => array ( 'blankets' => 1, 'sleepingbags' => 2, ), )

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