3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'KeyAccountID' => 1234, 'KeyAccountName' => 'John, Lennon', 'ClientID' => 9999, 'Client' => 'BBC', 'projects' => [ [2,915,'Zyxeldy','','',15000,'','',''], [2,956,'Awesome project, Step 1 ','','',1833.3333,1833.3333,1833.3333,''], [2,957,'Awesome project, Step 2','','',7000,'','',''] ] ],[ 'KeyAccountID' => 1236, 'KeyAccountName' => 'Ringo Starr', 'ClientID' => 9997, 'Client' => 'XYY', 'projects' => [ [2,867,'Data Mining','','',10000,'','',''] ] ],[ 'KeyAccountID' => 1235, 'KeyAccountName' => 'Poul McCartney', 'ClientID' => 9996, 'Client' => 'XYZ', 'projects' => [ [2,715,'XYZ, CSM','','',22083.3333,22083.3333,22083.3333,''] ] ] ]; $newArray = []; foreach($array as $value) { $newArray[$value['KeyAccountID']]['month1'] = array_sum(array_column($value['projects'],5)); $newArray[$value['KeyAccountID']]['month2'] = array_sum(array_column($value['projects'],6)); $newArray[$value['KeyAccountID']]['month3'] = array_sum(array_column($value['projects'],7)); } echo "<pre>"; var_dump($newArray); ?>
Output for git.master, git.master_jit
<pre>array(3) { [1234]=> array(3) { ["month1"]=> float(23833.3333) ["month2"]=> float(1833.3333) ["month3"]=> float(1833.3333) } [1236]=> array(3) { ["month1"]=> int(10000) ["month2"]=> int(0) ["month3"]=> int(0) } [1235]=> array(3) { ["month1"]=> float(22083.3333) ["month2"]=> float(22083.3333) ["month3"]=> float(22083.3333) } }
Output for rfc.property-hooks
Warning: array_sum(): Addition is not supported on type string in /in/UEFaB on line 35 Warning: array_sum(): Addition is not supported on type string in /in/UEFaB on line 35 Warning: array_sum(): Addition is not supported on type string in /in/UEFaB on line 36 Warning: array_sum(): Addition is not supported on type string in /in/UEFaB on line 36 Warning: array_sum(): Addition is not supported on type string in /in/UEFaB on line 35 Warning: array_sum(): Addition is not supported on type string in /in/UEFaB on line 36 <pre>array(3) { [1234]=> array(3) { ["month1"]=> float(23833.3333) ["month2"]=> float(1833.3333) ["month3"]=> float(1833.3333) } [1236]=> array(3) { ["month1"]=> int(10000) ["month2"]=> int(0) ["month3"]=> int(0) } [1235]=> array(3) { ["month1"]=> float(22083.3333) ["month2"]=> float(22083.3333) ["month3"]=> float(22083.3333) } }

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:
125.67 ms | 409 KiB | 5 Q